硒在python中无法在win7上打开chrome浏览器?
我想在Windows 7上使用python中的selenium webdriver打开chrome浏览器,但它挂起。下面是我使用的代码:硒在python中无法在win7上打开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")
`
你能帮助我吗?谢谢!
删除:
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驱动程序的烫发问题,请尝试将其移动到其他地方
谢谢你的回应。我尝试了这些包括和'browser = webdriver.Chrome(“C:\\ chromedriver.exe”)',但没有任何反应。在任务管理器中,我可以看到它打开了chromedriver,但没有chrome进程。你在Win7上运行它吗? – 2012-07-11 08:14:26
另外我必须指定我在64位平台上有win7。这是否会成为chromedriver打开Chrome浏览器的问题? – 2012-07-11 08:33:35
我做了一些更改,拿出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")
我看到你有一些调试代码在那里。它挂着什么电话?你是否收到任何错误输出? – 2012-07-10 13:38:33
这里没有任何错误。这里有两条最后一行的输出前挂: 二进制loc后 服务网址http:// localhost:64960 – 2012-07-10 13:54:29
有时达到最后,但它不打开浏览器。 – 2012-07-10 13:57:39