我试图在Windows 7上的python中使用selenium webdriver打开chrome浏览器,但它会挂起。以下是我使用的代码:
`
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint
chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
print "after binary loc"
browser = webdriver.Chrome("C:\\Python27\\chromedriver.exe", chrome_options=chromeOps)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")
`
你能帮帮我吗?谢谢!答案 0 :(得分:0)
卸下:
chromeOps = webdriver.ChromeOptions()
print "after chrome opts", chromeOps
print dir(chromeOps)
pprint(chromeOps)
chromeOps.binary_location = "C:\\Users\\cvoicu\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
print "after binary loc"
看看现在发生了什么。当我实例化chrome时,我只是设置了chromedriver的路径,它对我来说运行正常,也可能是在Python27中运行chrome驱动程序的perms问题,尝试将其移动到其他地方
答案 1 :(得分:0)
我做了一些更改,取出了ChromeOpts,因为我的电脑上没有该文件,它对我有用。确保将chromedriver添加到PATH
,你应该没问题。
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import *
import time
from pprint import pprint
import os
chromedriver = "C:\Users\USER\AppData\Local\Google\Chrome\Application\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
print "after binary loc"
browser = webdriver.Chrome(chromedriver)
print "after browser", browser
print dir(browser)
browser.get("http://www.google.com")