There is a question about PHP calling python. I hope to get your answer

CSDN Q & A 2022-01-15 04:17:31 阅读数:947

question php calling python. python

javacript The corresponding click event can run browser.py. But I can't see python The effect of opening the viewer . What's the reason for this . Hope to get an answer , thank you !!!
javascript:
I use ajax request :

$.ajax({ url: "http://localhost/test/diaoyongpy.php", cache: false, type: "POST", data: {
"button9":" Call viewer collection ","type":9}, dataType: "json", success:function(result) { alert(result); },error:function(msg){alert(" operation failed ");} });

diaoyongpy.php in :

$m=shell_exec('"D:\Program Files\Python3.7.3\python.exe" "D:\Program Files\xampp\htdocs\test\browser.py"');echo json_encode($m);

browser.py:

#coding=utf-8from selenium import webdriverimport pickleimport timeimport ioimport syssys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')url="https://www.baidu.com/"browser = webdriver.Chrome()browser.get(url)text=browser.page_sourceprint (text)browser.quit()

You can get the source code of the web page , But I can't see py The viewer opened after being called . This has bothered me for a long time . I don't know why . What changes do you want . I use xampp Build a local test environment . Thank you again for !!




Refer to the answer 1:

Will it be too soon , In a flash . Or take it browser.quit() Get rid of , See if the browser is still .




Refer to the answer 2:
版权声明:本文为[CSDN Q & A]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2021/12/202112121855030827.html