0

I want to pass the variable from php to python and i use this code for that:

php

<?php

    $item='http://www.google.com';
    $tmp  = passthru("python test.py ".$item);

python

from selenium import webdriver
import sys
link = sys.argv[1]
chrome_path = r"C:\Users\user\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get(link)
s = driver.page_source

and this works fine, but now in this process, I want to pass this variable s from python in the PHP, can I do it somehow in one step, when I pass the variable from PHP to python to receive the result of python code again in the PHP

6
  • try using shell_exec, using shell_exec run your python script which returns a json, this will get stored in your shell_exec var. Won't this work? Commented Jul 8, 2019 at 18:08
  • $tmp = shell_exec('python test.py ' . $item); Commented Jul 8, 2019 at 18:14
  • this does not work Commented Jul 8, 2019 at 18:14
  • this does not work because your python script is not giving any output Commented Jul 8, 2019 at 18:15
  • so what should i add? Commented Jul 8, 2019 at 18:18

1 Answer 1

1

This should work

from selenium import webdriver
....# your code here
print(driver.page_source)

in PHP

$tmp = shell_exec('python test.py ' . $item);

Now your $tmp should have driver.page_source value

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

2 Comments

i dont know why, but this dont works for me, shell_exec does not works, only passthru
@dssada what's your python version?

Your Answer

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