from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'/usr/local/bin/google-chrome')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
我收到此错误:
File "test.py", line 5, in <module>
driver = webdriver.Chrome(executable_path=r'/usr/bin/google-chrome')
File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 1
我尝试了互联网上的其他解决方案,但我尝试的每个解决方案都收到了一个新错误。我只想使用python硒和chrome驱动程序获取页面源代码,我不知道为什么没有解决方案对我有用,有什么帮助吗?
我在客户端服务器中执行此操作,在我的本地 im 中使用 Windows 并且它的工作很好,但是它的代码不同......
此错误消息...
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 1
。暗示ChromeDriver无法启动/生成新的浏览上下文,即Chrome浏览器会话。
看来你很接近。通过密钥executable_path
而不是二进制文件的绝对路径google-chrome
您需要将ChromeDriver的绝对路径作为值传递。如此有效地,您需要替换代码行:
driver = webdriver.Chrome(executable_path=r'/usr/local/bin/google-chrome')
跟:
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
安装此软件包并重试:
apt-get install -y libglib2.0-0=2.50.3-2
libnss3=2:3.26.2-1.1+deb9u1
libgconf-2-4=3.2.6-4+b1
libfontconfig1=2.11.0-6.7+b1
或者你可以安装铬浏览器:
sudo apt-get install -y chromium-browser