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?
-
1while 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?Danyal Sandeelo– Danyal Sandeelo2019年04月25日 06:51:45 +00:00Commented 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.Klaus D.– Klaus D.2019年04月25日 06:55:48 +00:00Commented Apr 25, 2019 at 6:55
-
Thanks, @DanyalSandeelo for guiding.Subham– Subham2019年04月25日 07:41:30 +00:00Commented Apr 25, 2019 at 7:41
1 Answer 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.
2 Comments
Explore related questions
See similar questions with these tags.