我是编程的新手,Python大约2个月前开始使用Python文本,正在浏览Sweigart的自动化无聊的东西.我正在使用IDLE并且已经安装了selenium模块和Firefox浏览器.每当我尝试运行webdriver函数时,我都会得到:
from selenium import webdriver
browser = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
例外: -
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File …Run Code Online (Sandbox Code Playgroud) 我现在正在学习Selenium,遇到了一个问题.
我知道Selenium默认支持旧的Firefox版本,没有驱动程序.对于最新版本的Firefox,我们必须下载驱动程序并使用它来定义它System.setProperty.
根据此链接,对于Firefox 45和46,启动驱动程序代码可能如下所示:
WebDriver driver = new FirefoxDriver();
Run Code Online (Sandbox Code Playgroud)
我的Firefox版本为45.5.1.但是上面的代码仍然不起作用.所以根据这个链接,我添加了:
System.setProperty("webdriver.firefox.marionette","C:\\geckodriver.exe");
它奏效了.
然后我意识到我没有安装geckodriver.exe在我的电脑上.要了解它是如何进行的,我已经更改为以下代码:
System.setProperty("webdriver.firefox.marionette","");
Run Code Online (Sandbox Code Playgroud)
它仍然有效.
所以,这是我的第一个问题:发生了什么?我确信geckodriver.exe在我的环境中不存在.如果没有指出位置,那我为什么要设置属性?
另外,我见过的代码如下:
System.setProperty("webdriver.gecko.driver", "/tools/marionette/wires.exe");
Run Code Online (Sandbox Code Playgroud)
我的第二个问题是,是什么样的区别webdriver.gecko.driver 和webdriver.firefox.marionette或wires.exe和geckodriver.exe?
selenium selenium-firefoxdriver selenium-webdriver firefox-marionette geckodriver
我正在使用Firefox 47.0和Selenium 2.53.最近他们一直是Selenium和Firefox之间的一个错误,它使代码无效.其中一个解决方案是使用Marionnette驱动程序.
我按照本网站的说明使用这个新驱动程序与RemotWebDriver,但我一直有错误:
WARN - 异常:线程"main"中的异常org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置; 有关更多信息,请参阅https://github.com/jgraham/wires.最新版本可以从....下载
我到目前为止尝试的代码非常简单:
public class Test {
static WebDriver driver;
static Wait<WebDriver> wait;
public static void main(String[] args) throws MalformedURLException {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability("marionette", true);
cap.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL("http://192.168.117.135:5555/wd/hub"), cap);//true to enable the JS
wait = new WebDriverWait(driver, 3000);
final String url = "https://www.google.com/";
JavascriptExecutor js = (JavascriptExecutor) driver;
try {
driver.navigate().to(url);
} finally {
driver.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我确定geckodriver.exe的路径是正确的,我不知道我在哪里做错了.
编辑1:我尝试了以下代码:
public class Test …Run Code Online (Sandbox Code Playgroud) 我在使用 Google 登录时遇到问题。我想登录我的帐户,但 Google 说不允许自动化驱动程序登录。
我正在寻找解决方案。是否可以获取普通 Firefox/Chrome 的 cookie 并将其加载到 ChromeDriver/GeckoDriver 中?我认为这可以是一个解决方案。但我不确定这是否可能..
正在寻找解决方案...
另外,我想添加一个快速解决方案。我通过使用我的旧验证帐户之一解决了这个问题。这对你来说是一个快速的解决方案。
selenium google-chrome selenium-chromedriver selenium-webdriver geckodriver
我在以下代码中使用 geckodriver:
import time
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
url = 'https://www.idealista.com/venta-viviendas/barcelona/eixample/la-dreta-de-l-eixample/?ordenado-por=fecha-publicacion-desc'
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options, executable_path='/home/kevin/Desktop/Inmosoft/geckodriver')
driver.get(url)
time.sleep(10)
Run Code Online (Sandbox Code Playgroud)
但每次我尝试执行时都会出现此错误:
我尝试按照此链接https://support.mozilla.org/en-US/kb/how-run-firefox-when-profile-missing-inaccessiblefirefox -P中的信息在 Firefox 中创建另一个配置文件。
看起来 geckodriver 与 firefox 是一个完全不同的实例,并且它不使用相同的配置文件,我如何在使用 geckodriver 时绕过此错误并创建配置文件?
我试图在Python中使用Selenium.但是,从https://pypi.python.org/pypi/selenium给出以下内容我不知道该怎么做
Selenium需要驱动程序与所选浏览器进行交互.例如,Firefox需要geckodriver,需要在运行以下示例之前安装geckodriver.确保它在您的PATH中,例如,将其放在/ usr/bin或/ usr/local/bin中.
我正在运行Windows 7 32位.我在这里找到了geckodriver:https://github.com/mozilla/geckodriver/releases
我大多使用Anaconda分发的Python来处理excel,所以我不知道什么是"PATH"
谢谢,
我更新了PATH,如评论中所示.这是完整的错误回溯.
Microsoft Windows [版本6.1.7601]版权所有(c)2009 Microsoft Corporation.版权所有.
C:\ Users \用户用户1>蟒
Python 3.5.2 | Anaconda 4.2.0(32位)| (默认,2016年7月5日,11:45:57)[winv上的MSC v.1 900 32位(英特尔)]输入"帮助","版权","信用"或"许可证"以获取更多信息.
来自selenium import webdriver driver = webdriver.Firefox()
回溯(最近一次调用最后一次):文件"",第1行,文件"C:\ Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\webdriver.py",li ne 80,在init self.binary中,超时)文件"C:\ Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53 .6-py3.5.egg\selenium\webdriver\firefox\extension_connect ion.py",第52行,在init self.binary.launch_browser(self.profile,timeout = timeout)文件"C:\ Users\user1\AppData\local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py",第67行,在launch_browser self._start_from_profile_path(self.profile.path) )文件"C:\ Users\user1\AppData\Local\Continuum\Anaconda3\lib\site -packages\selenium-2.53.6-py3.5.egg\selenium\webdriver\firefox\firefox_binary.py",第90行, in _start_from_profile_path env = self._firefox_env)文件"C:\ Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py",第947行,在init restore_中 signal,start_new_session)文件"C:\ Users\user1\AppData\Local\Continuum\Anaconda3\lib\subp rocess.py",第1224行,在_execute_child startupinfo中)FileNotFoundError:[WinError 2]系统找不到指定的文件
>
我正在使用一个非常复杂的设置来测试各种非公共网页.我用它jenkins来运行图像中的python-selenium测试docker.这样,我完全独立于jenkins环境,可以创建自己的环境.在这种环境中,我安装了以下软件:
硒测试创建WebDriver以下方式:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.dir", self.downloadpath)
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.useDownloadDir", True)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("pdfjs.disabled", True)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk",
"application/force-download, image/png, text/html, text/plain, "
"image/tiff, text/csv, application/zip, application/octet-stream")
profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
profile.set_preference("browser.download.manager.focusWhenStarting", False)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.download.manager.alertOnEXEOpen", False)
profile.set_preference("browser.download.manager.closeWhenDone", True)
profile.set_preference("browser.download.manager.showAlertOnComplete", False)
profile.set_preference("browser.download.manager.useWindow", False)
profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting",
False)
self.driver = webdriver.Firefox(profile, log_path = logfile)
Run Code Online (Sandbox Code Playgroud)
其中,logfile和self.downloadpath是在泊坞窗设置两个有效的路径.
整个测试套件包含6个独立的测试用例,每个测试用例具有与上述相同的设置.他们通常运行良好,完整没有问题.
但是,如果没有对测试或常规设置进行任何更改,测试有时会失败,并显示以下错误消息:
File "/root/tests/bsp_usecase_tests/tools/basicsuite.py", line 210, in set_driver_firefox
self.driver = webdriver.Firefox(profile, log_path …Run Code Online (Sandbox Code Playgroud) 服务器:Raspberry Pi 3
OS:Dietpi - 版本159
Geckodriver版本:0.22 for arm
Firefox版本:52.9.0
Python版本:3.5
Selenium版本:3.14.1
Gecko是可执行的,位于/ usr/local/bin /
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)
print('Need your login credential')
username = input('What is your username?:\n')
password = input('What is your password?:\n')
...
...
Run Code Online (Sandbox Code Playgroud)
输出:
root@RPi3:~# python3.5 ITE-bot.py
Traceback (most recent call last):
File "ITE-bot.py", line 12, in <module>
driver …Run Code Online (Sandbox Code Playgroud) 我必须在这里找到一些不匹配的版本,因为我无法使用Python启动Selenium来启动Firefox Web浏览器.我使用的是旧版本的Firefox,因为这里的其他人拥有相同的旧版本的Python,对于他们来说,旧版本的Firefox效果最好.
码:
from selenium import webdriver
from selenium import common
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "scrapeCommunitySelenium.py", line 13, in <module>
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
keep_alive=True)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters) …Run Code Online (Sandbox Code Playgroud) 美好的一天,我已经在这里和谷歌进行了一些搜索,但还没有找到解决这个问题的解决方案.
场景是:
我有一个Python脚本(2.7)循环遍历许多URL(例如,想想亚马逊页面,抓取评论).每个页面都有相同的HTML布局,只是抓取不同的信息.我使用Selenium和无头浏览器,因为这些页面需要执行javascript以获取信息.
我在本地计算机上运行此脚本(OSX 10.10).Firefox是最新的v59.Selenium版本为3.11.0,使用geckodriver v0.20.
这个脚本在本地没有问题,它可以运行所有的URL并刮除页面没有问题.
现在,当我将脚本放在我的服务器上时,唯一的区别是它是Ubuntu 16.04(32位).我使用适当的geckodriver(仍然是v0.20),但其他一切都是相同的(Python 2.7,Selenium 3.11).它似乎随机崩溃无头浏览器,然后所有browserObjt.get('url...')不再工作.
错误消息说:
消息:无法解读牵线木偶的响应
任何进一步的页面selenium请求都会返回错误:
消息:尝试在不建立连接的情况下运行命令
要显示一些代码:
当我创建驱动程序时:
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(
firefox_options=options,
executable_path=config.GECKODRIVER
)
Run Code Online (Sandbox Code Playgroud)
driver作为参数传递给脚本的函数,browserObj然后用于调用特定页面,然后一旦加载它就传递给BeautifulSoup进行解析:
browserObj.get(url)
soup = BeautifulSoup(browserObj.page_source, 'lxml')
Run Code Online (Sandbox Code Playgroud)
该错误可能指向正在崩溃浏览器的BeautifulSoup行.
可能导致此问题的原因,我该怎么做才能解决问题?
编辑:添加指向同一事物的堆栈跟踪:
Traceback (most recent call last):
File "main.py", line 164, in <module>
getLeague
File "/home/ps/dataparsing/XXX/yyy.py", line 48, in BBB
soup = BeautifulSoup(browserObj.page_source, 'lxml')
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 670, in page_source
return self.execute(Command.GET_PAGE_SOURCE)['value']
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", …Run Code Online (Sandbox Code Playgroud)