PHP exec python脚本运行Selenium

时间:2018-04-12 19:25:09

标签: php python windows selenium-webdriver geckodriver

我正在尝试从使用Selenium的PHP(使用Laravel)运行python脚本 - > Firefox浏览器。

它现在运行最新的firefox,selenium 3.11.0和geckodriver 0.20.0

当我从PHP运行python脚本 test.py 时:

    $scrape = 'python '.base_path().'Description\test.py 2>&1';
    $output = shell_exec($scrape);
    echo($output);

test.py 的位置为:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

options = Options()
print("Created Options")
options.add_argument("--headless")
print("Added options")
binary = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")
fp = webdriver.FirefoxProfile()
print("Binary set up")
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp, firefox_options = options)
driver.get("http://www.google.com")
print("Going to URL")
driver.quit()
print("Quit")

我授予python,geckdodriver和firefox的整个lib目录的权限,以便在IIS_IUSRS(使用Windows)下拥有完全控制权。

geckodriver的日志

1523551010316   geckodriver INFO    geckodriver 0.19.0
1523551010337   geckodriver INFO    Listening on 127.0.0.1:55452
1523552906639   geckodriver INFO    geckodriver 0.19.0
1523552906660   geckodriver INFO    Listening on 127.0.0.1:64886
1523552982150   geckodriver INFO    geckodriver 0.19.0
1523552982157   geckodriver INFO    Listening on 127.0.0.1:65274
1523552996397   geckodriver INFO    geckodriver 0.19.0
1523552996403   geckodriver INFO    Listening on 127.0.0.1:65361
1523553042485   geckodriver INFO    geckodriver 0.19.0
1523553042491   geckodriver INFO    Listening on 127.0.0.1:49225
1523553453916   geckodriver INFO    geckodriver 0.19.0
1523553453924   geckodriver INFO    Listening on 127.0.0.1:51324
1523553557325   geckodriver INFO    geckodriver 0.19.0
1523553557332   geckodriver INFO    Listening on 127.0.0.1:51851
1523553572336   geckodriver INFO    geckodriver 0.19.0
1523553572343   geckodriver INFO    Listening on 127.0.0.1:51943
1523553584227   geckodriver INFO    geckodriver 0.19.0
1523553584236   geckodriver INFO    Listening on 127.0.0.1:52020
1523553969221   geckodriver INFO    geckodriver 0.19.0
1523553969254   geckodriver INFO    Listening on 127.0.0.1:53947
1523554425807   geckodriver INFO    geckodriver 0.19.0
1523554425830   geckodriver INFO    Listening on 127.0.0.1:56253
1523554461095   geckodriver INFO    geckodriver 0.19.0
1523554461102   geckodriver INFO    Listening on 127.0.0.1:56446
1523554524912   geckodriver INFO    geckodriver 0.19.0
1523554524919   geckodriver INFO    Listening on 127.0.0.1:56788
1523554661450   geckodriver INFO    geckodriver 0.19.0
1523554661457   geckodriver INFO    Listening on 127.0.0.1:57478
1523554945239   geckodriver INFO    geckodriver 0.19.0
1523554945245   geckodriver INFO    Listening on 127.0.0.1:58934
1523555132097   geckodriver INFO    geckodriver 0.19.0
1523555132104   geckodriver INFO    Listening on 127.0.0.1:59859
1523555833096   geckodriver INFO    geckodriver 0.19.0
1523555833171   geckodriver INFO    Listening on 127.0.0.1:63326
1523556541828   geckodriver INFO    geckodriver 0.19.0
1523556541849   geckodriver INFO    Listening on 127.0.0.1:50425
1523557052268   geckodriver INFO    geckodriver 0.19.0
1523557052288   geckodriver INFO    Listening on 127.0.0.1:53022
1523557865989   geckodriver INFO    geckodriver 0.19.0
1523557865996   geckodriver INFO    Listening on 127.0.0.1:57094
1523558364753   geckodriver INFO    geckodriver 0.19.0
1523558364761   geckodriver INFO    Listening on 127.0.0.1:59596
1523558692756   geckodriver INFO    geckodriver 0.19.0
1523558692763   geckodriver INFO    Listening on 127.0.0.1:61265
1523559379217   geckodriver INFO    geckodriver 0.19.0
1523559379240   geckodriver INFO    Listening on 127.0.0.1:64505
1523559433741   geckodriver INFO    geckodriver 0.19.0
1523559433763   geckodriver INFO    Listening on 127.0.0.1:64792
1523559454014   geckodriver INFO    geckodriver 0.19.0
1523559454021   geckodriver INFO    Listening on 127.0.0.1:64913
1523559499598   geckodriver INFO    geckodriver 0.19.0
1523559499605   geckodriver INFO    Listening on 127.0.0.1:65159
1523559825949   geckodriver INFO    geckodriver 0.19.0
1523559825956   geckodriver INFO    Listening on 127.0.0.1:50459
1523559827139   geckodriver INFO    geckodriver 0.19.0
1523559827146   geckodriver INFO    Listening on 127.0.0.1:50470
1523560435473   geckodriver INFO    geckodriver 0.19.0
1523560435531   geckodriver INFO    Listening on 127.0.0.1:53559
1523562230663   geckodriver INFO    geckodriver 0.19.0
1523562230687   geckodriver INFO    Listening on 127.0.0.1:62289
1523564088330   geckodriver INFO    geckodriver 0.19.0
1523564088338   geckodriver INFO    Listening on 127.0.0.1:54981
1523564554561   geckodriver INFO    geckodriver 0.19.0
1523564554582   geckodriver INFO    Listening on 127.0.0.1:57277
1523564576099   geckodriver INFO    geckodriver 0.19.0
1523564576106   geckodriver INFO    Listening on 127.0.0.1:57397
1523564596509   geckodriver INFO    geckodriver 0.19.0
1523564596517   geckodriver INFO    Listening on 127.0.0.1:57517
1523566668455   geckodriver INFO    geckodriver 0.19.0
1523566668462   geckodriver INFO    Listening on 127.0.0.1:51277
1523566841445   geckodriver INFO    geckodriver 0.19.0
1523566841453   geckodriver INFO    Listening on 127.0.0.1:52131
1523567215532   geckodriver INFO    geckodriver 0.19.0
1523567215540   geckodriver INFO    Listening on 127.0.0.1:53967
1523567239768   geckodriver INFO    geckodriver 0.19.0
1523567239776   geckodriver INFO    Listening on 127.0.0.1:54103
1523567265282   geckodriver INFO    geckodriver 0.19.0
1523567265288   geckodriver INFO    Listening on 127.0.0.1:54242
1523567277430   geckodriver INFO    geckodriver 0.19.0
1523567277438   geckodriver INFO    Listening on 127.0.0.1:54321
1523567285360   geckodriver INFO    geckodriver 0.19.0
1523567285367   geckodriver INFO    Listening on 127.0.0.1:54375
1523567562191   geckodriver INFO    geckodriver 0.19.0
1523567562199   geckodriver INFO    Listening on 127.0.0.1:55752
1523568013582   geckodriver INFO    geckodriver 0.19.0
1523568013603   geckodriver INFO    Listening on 127.0.0.1:58035
1523568126114   geckodriver INFO    geckodriver 0.19.0
1523568126121   geckodriver INFO    Listening on 127.0.0.1:58597
1523568204080   geckodriver INFO    geckodriver 0.19.0
1523568204089   geckodriver INFO    Listening on 127.0.0.1:58995
1523568236866   geckodriver INFO    geckodriver 0.19.0
1523568236873   geckodriver INFO    Listening on 127.0.0.1:59169
1523568365663   geckodriver INFO    geckodriver 0.19.0
1523568365670   geckodriver INFO    Listening on 127.0.0.1:59651
1523568583373   geckodriver INFO    geckodriver 0.19.0
1523568583380   geckodriver INFO    Listening on 127.0.0.1:60709
1523568984663   geckodriver INFO    geckodriver 0.19.0
1523568984683   geckodriver INFO    Listening on 127.0.0.1:62636
1523569163782   geckodriver INFO    geckodriver 0.19.0
1523569163804   geckodriver INFO    Listening on 127.0.0.1:63502
1523579734024   geckodriver INFO    geckodriver 0.19.0
1523579734046   geckodriver INFO    Listening on 127.0.0.1:49377
1523581385149   geckodriver INFO    geckodriver 0.19.0
1523581385171   geckodriver INFO    Listening on 127.0.0.1:57493
1523581448830   geckodriver INFO    geckodriver 0.19.0
1523581448845   geckodriver INFO    Listening on 127.0.0.1:57821
1523607057941   geckodriver INFO    geckodriver 0.19.0
1523607058145   geckodriver INFO    Listening on 127.0.0.1:50889
1523607183263   geckodriver INFO    geckodriver 0.19.0
1523607183306   geckodriver INFO    Listening on 127.0.0.1:51099
1523607240431   geckodriver INFO    geckodriver 0.19.0
1523607240511   geckodriver INFO    Listening on 127.0.0.1:51195
1523623712258   geckodriver INFO    geckodriver 0.19.0
1523623712386   geckodriver INFO    Listening on 127.0.0.1:49413
1523624414430   geckodriver INFO    geckodriver 0.19.0
1523624414437   geckodriver INFO    Listening on 127.0.0.1:49491
1523624471867   geckodriver INFO    geckodriver 0.19.0
1523624471873   geckodriver INFO    Listening on 127.0.0.1:49514
1523624716169   geckodriver INFO    geckodriver 0.19.0
1523624716175   geckodriver INFO    Listening on 127.0.0.1:49544
1523624783033   geckodriver INFO    geckodriver 0.19.0
1523624783040   geckodriver INFO    Listening on 127.0.0.1:49566
1523625431597   geckodriver INFO    geckodriver 0.19.0
1523625431603   geckodriver INFO    Listening on 127.0.0.1:49616
1523625702932   geckodriver INFO    geckodriver 0.19.0
1523625702939   geckodriver INFO    Listening on 127.0.0.1:49644
1523641970187   geckodriver INFO    geckodriver 0.19.0
1523641970231   geckodriver INFO    Listening on 127.0.0.1:50576
1523642534699   geckodriver INFO    geckodriver 0.19.0
1523642534706   geckodriver INFO    Listening on 127.0.0.1:50625
1523642573251   geckodriver INFO    geckodriver 0.19.0
1523642573257   geckodriver INFO    Listening on 127.0.0.1:50647
1523642715989   geckodriver INFO    geckodriver 0.19.0
1523642715996   geckodriver INFO    Listening on 127.0.0.1:50672
1523643125879   geckodriver INFO    geckodriver 0.19.0
1523643125885   geckodriver INFO    Listening on 127.0.0.1:50705
1523643319804   geckodriver INFO    geckodriver 0.19.0
1523643319810   geckodriver INFO    Listening on 127.0.0.1:50741
1523645004597   geckodriver INFO    geckodriver 0.19.0
1523645004604   geckodriver INFO    Listening on 127.0.0.1:50822
1523645077355   geckodriver INFO    geckodriver 0.19.0
1523645077361   geckodriver INFO    Listening on 127.0.0.1:50844
1523645468905   geckodriver INFO    geckodriver 0.19.0
1523645468912   geckodriver INFO    Listening on 127.0.0.1:50887
1523645536572   geckodriver INFO    geckodriver 0.19.0
1523645536579   geckodriver INFO    Listening on 127.0.0.1:50911
1523645646052   geckodriver INFO    geckodriver 0.19.0
1523645646060   geckodriver INFO    Listening on 127.0.0.1:50934
1523646298145   geckodriver INFO    geckodriver 0.19.0
1523646298151   geckodriver INFO    Listening on 127.0.0.1:50983
1523646904316   geckodriver INFO    geckodriver 0.19.0
1523646904323   geckodriver INFO    Listening on 127.0.0.1:51024
1523647702202   geckodriver INFO    geckodriver 0.19.0
1523647702209   geckodriver INFO    Listening on 127.0.0.1:51127
1523647800626   geckodriver INFO    geckodriver 0.19.0
1523647800633   geckodriver INFO    Listening on 127.0.0.1:51149
1523647849026   geckodriver INFO    geckodriver 0.19.0
1523647849032   geckodriver INFO    Listening on 127.0.0.1:51170
1523647970017   geckodriver INFO    geckodriver 0.19.0
1523647970024   geckodriver INFO    Listening on 127.0.0.1:51205
1523647982449   geckodriver INFO    geckodriver 0.19.0
1523647982456   geckodriver INFO    Listening on 127.0.0.1:51225
1523648024245   geckodriver INFO    geckodriver 0.19.0
1523648024251   geckodriver INFO    Listening on 127.0.0.1:51246
1523648280882   geckodriver INFO    geckodriver 0.19.0
1523648280889   geckodriver INFO    Listening on 127.0.0.1:51275
1523648711661   geckodriver INFO    geckodriver 0.19.0
1523648711710   geckodriver INFO    Listening on 127.0.0.1:51304
1523648876955   geckodriver INFO    geckodriver 0.19.0
1523648876962   geckodriver INFO    Listening on 127.0.0.1:51342
1523648981745   geckodriver INFO    geckodriver 0.19.0
1523648981752   geckodriver INFO    Listening on 127.0.0.1:51364
1523649029576   geckodriver INFO    geckodriver 0.19.0
1523649029582   geckodriver INFO    Listening on 127.0.0.1:51383
1523650025386   geckodriver INFO    geckodriver 0.19.0
1523650025392   geckodriver INFO    Listening on 127.0.0.1:51443
1523650231426   geckodriver INFO    geckodriver 0.19.0
1523650231447   geckodriver INFO    Listening on 127.0.0.1:51512
1523650784379   geckodriver INFO    geckodriver 0.19.0
1523650784400   geckodriver INFO    Listening on 127.0.0.1:51676
1523651138455   geckodriver INFO    geckodriver 0.20.1
1523651138478   geckodriver INFO    Listening on 127.0.0.1:51722
1523651421970   geckodriver INFO    geckodriver 0.20.1
1523651421979   geckodriver INFO    Listening on 127.0.0.1:51816
1523651539385   geckodriver INFO    geckodriver 0.20.1
1523651539393   geckodriver INFO    Listening on 127.0.0.1:51845
1523651563942   geckodriver INFO    geckodriver 0.20.1
1523651563953   geckodriver INFO    Listening on 127.0.0.1:51867
1523651617176   geckodriver INFO    geckodriver 0.20.1
1523651617184   geckodriver INFO    Listening on 127.0.0.1:51898
1523651955634   geckodriver INFO    geckodriver 0.20.1
1523651955642   geckodriver INFO    Listening on 127.0.0.1:51933
1523651972841   geckodriver INFO    geckodriver 0.20.1
1523651972849   geckodriver INFO    Listening on 127.0.0.1:51954
1523652422260   geckodriver INFO    geckodriver 0.20.1
1523652422269   geckodriver INFO    Listening on 127.0.0.1:51990
1523652679606   geckodriver INFO    geckodriver 0.20.0
1523652679631   geckodriver INFO    Listening on 127.0.0.1:52034
1523653035745   geckodriver INFO    geckodriver 0.20.0
1523653035754   geckodriver INFO    Listening on 127.0.0.1:52112
1523653444434   geckodriver INFO    geckodriver 0.20.0
1523653444442   geckodriver INFO    Listening on 127.0.0.1:52201
1523653445096   geckodriver INFO    geckodriver 0.20.0
1523653445104   geckodriver INFO    Listening on 127.0.0.1:52206
1523653445765   geckodriver INFO    geckodriver 0.20.0
1523653445773   geckodriver INFO    Listening on 127.0.0.1:52217
1523653447197   geckodriver INFO    geckodriver 0.20.0
1523653447205   geckodriver INFO    Listening on 127.0.0.1:52229
1523653447399   geckodriver INFO    geckodriver 0.20.0
1523653447408   geckodriver INFO    Listening on 127.0.0.1:52231
1523653455732   geckodriver INFO    geckodriver 0.20.0
1523653455740   geckodriver INFO    Listening on 127.0.0.1:52257
1523653695320   geckodriver INFO    geckodriver 0.20.0
1523653695328   geckodriver INFO    Listening on 127.0.0.1:52287
1523656451072   geckodriver INFO    geckodriver 0.20.0
1523656451081   geckodriver INFO    Listening on 127.0.0.1:52419
1523702123572   geckodriver INFO    geckodriver 0.20.0
1523702123607   geckodriver INFO    Listening on 127.0.0.1:54308
1523702293855   geckodriver INFO    geckodriver 0.20.0
1523702293864   geckodriver INFO    Listening on 127.0.0.1:54335

产生错误:

  

文件   “C:\ inetpub \ wwwroot \ jobDescription \ test.py”,第13行,在driver =中   webdriver.Firefox(firefox_options = options,firefox_binary = binary)   文件   “C:\用户\管理\应用程序数据\本地\程序\ Python的\ Python36-32 \ LIB \站点包\硒\ webdriver的\火狐\ webdriver.py”   第162行,在 init keep_alive = True)文件中   “C:\用户\管理\应用程序数据\本地\程序\ Python的\ Python36-32 \ LIB \站点包\硒\ webdriver的\遥控\ webdriver.py”   第154行,在 init self.start_session(desired_capabilities,   browser_profile)文件   “C:\用户\管理\应用程序数据\本地\程序\ Python的\ Python36-32 \ LIB \站点包\硒\ webdriver的\遥控\ webdriver.py”   第243行,在start_session响应中=   self.execute(Command.NEW_SESSION,参数)文件   “C:\用户\管理\应用程序数据\本地\程序\ Python的\ Python36-32 \ LIB \站点包\硒\ webdriver的\遥控\ webdriver.py”   第312行,执行self.error_handler.check_response(response)文件   “C:\用户\管理\应用程序数据\本地\程序\ Python的\ Python36-32 \ LIB \站点包\硒\ webdriver的\遥控\ errorhandler.py”   第242行,在check_response中引发exception_class(消息,屏幕,   stacktrace)selenium.common.exceptions.WebDriverException:消息:   许可被拒绝

1 个答案:

答案 0 :(得分:0)

好的,所以这将是我收到的每个错误的所有答案的列表,这可能有助于未来的人。

  

WebDriverException:消息:无法找到匹配的一组   功能

当您的某个程序过期时,似乎会运行此错误。 IE:Selenium / Firefox / Geckodriver。我建议更新它们/检查它们是否相互兼容某些版本彼此不兼容)。

  

WebDriverException:消息:权限被拒绝

如果您使用IIS,则需要更改应用程序池标识。

IIS->需要访问的网站 - 身份验证设置 - >匿名身份验证 - >编辑 - >选择应用程序池标识(而不是IUSER)。

  

WebDriverException:消息:进程意外关闭,状态为:0

更新geckodriver

  

WebDriverException:消息:连接重置

尝试使用Nightly版本的Firefox并更新它的二进制路径。