日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

php调用selenium,通过PHP exec()执行Selenium webdriver

發(fā)布時(shí)間:2024/9/27 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php调用selenium,通过PHP exec()执行Selenium webdriver 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我構(gòu)建了一個(gè)python腳本,它使用Selenium和Firefox加載一些網(wǎng)站并處理它們的內(nèi)容。因?yàn)槲蚁朐赑HP中使用該腳本的輸出,所以我使用PHP的exec()函數(shù)。在

我的python測(cè)試腳本如下所示:from pyvirtualdisplay import Display

from selenium import webdriver

import sys

display = Display(visible=0, size=(800, 600))

display.start()

driver = webdriver.Firefox()

print("Driver started")

driver.quit()

display.stop()

當(dāng)從命令行運(yùn)行它時(shí),我得到預(yù)期的“驅(qū)動(dòng)程序啟動(dòng)”輸出。在

但是,在這樣的PHP腳本中運(yùn)行它時(shí):

^{pr2}$

python腳本產(chǎn)生以下錯(cuò)誤:Traceback (most recent call last):

File "test.py", line 8, in

driver = webdriver.Firefox()

File "/usr/lib/python2.6/site-packages/selenium-3.4.3-py2.6.egg/selenium/webdriver/firefox/webdriver.py", line 152, in __init__

keep_alive=True)

File "/usr/lib/python2.6/site-packages/selenium-3.4.3-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 98, in __init__

self.start_session(desired_capabilities, browser_profile)

File "/usr/lib/python2.6/site-packages/selenium-3.4.3-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 188, in start_session

response = self.execute(Command.NEW_SESSION, parameters)

File "/usr/lib/python2.6/site-packages/selenium-3.4.3-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 256, in execute

self.error_handler.check_response(response)

File "/usr/lib/python2.6/site-packages/selenium-3.4.3-py2.6.egg/selenium/webdriver/remote/errorhandler.py", line 194, in check_response

raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

我還應(yīng)該提到,在命令行中,我嘗試以root用戶和另一個(gè)用戶的身份運(yùn)行腳本,兩個(gè)用戶都有效。web服務(wù)器正在使用“nginx”用戶執(zhí)行它,我無(wú)法在命令行上看到它,因?yàn)樗粀eb服務(wù)器占用了。但是我假設(shè),就像我的測(cè)試用戶一樣,nginx用戶也應(yīng)該擁有運(yùn)行腳本所需的所有權(quán)限。在

Firefox版本:Mozilla Firefox 52.1.0

Selenium版本:3.4.3

Geckodriver版本:0.16.1

更新

嘗試從php運(yùn)行Firefox等可執(zhí)行文件,但這也不起作用。在

總結(jié)

以上是生活随笔為你收集整理的php调用selenium,通过PHP exec()执行Selenium webdriver的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。