0

I have created a Python script that scrapes the data on the website after logging in based on the Start Date and End Date and stored in JSON. It works fine since I am passing dates static in script But I want to pass those two dates from PHP as parameters to Python script and pass those JSON data to the client side(in PHP) as Response. I have used requests and BeautifulSoap for this. I am stuck in Dynamic part? Can you guide me on how to do this?

3
  • 1
    while running the python script, you can pass runtime arguments right? pass the star time and end time as arguments to the python call, the response can be received via exec(" python script.py startime endtime") ?? no? Commented Apr 25, 2019 at 6:51
  • Stack Overflow is a website where you get specific answers to specific questions related to programming. Guiding you through your project is not a service we offer here. Commented Apr 25, 2019 at 6:55
  • Thanks, @DanyalSandeelo for guiding. Commented Apr 25, 2019 at 7:41

1 Answer 1

1

In PHP you can do something like:

<?php
    $start_date = "2019-04-26";
    $end_date = "2019-04-30";
    $command = "/path/to/script/script.py -s $start_date -e $end_date";
    exec($command);
?>

AND Python Script:

import sys
count = 0
for arg in sys.argv:
    if arg == "-s":
        START = sys.argv[count+1]
    elif arg == "-e":
        END = sys.argv[count+1]
    count+=1
# Here you will get your START & END date.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. It works.fine on the local machine. I got what I want But How to execute if Python file is on different Server?
You can use absolute path of script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.