我希望每个人都很好。 我是python中的一个新手,很多人运行这个代码,但我无法理解问题是什么以及我如何解决这个问题。
我的代码是:
from selenium import webdriver
from time import sleep
url = raw_input("Enter URL to get visits (With http://): ")
proxy_path = raw_input("Enter path to proxy file:")
with open(proxy_path) as f:
content = f.readlines()
f.close()
proxies = 0
with open(proxy_path) as infp:
for line in infp:
if line.strip():
proxies += 1
print 'Loaded %d proxies' %proxies
# For debugging purposes
#print content[run_through]
run_through = 1
while True:
#print "Start of loop"
print "Ran %s times" %run_through
try:
use_proxy = content[run_through]
except IndexError:
print "Out of proxies"
break
print "Using: %s" %use_proxy
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' %use_proxy)
chrome_options.binary_location(value = u"C:\\ProgramFiles\\Google\\Chrome\\chrome.exe")
browser = webdriver.Chrome(chrome_options=chrome_options)
#print "Browser started"
try:
browser.get(url)
#print "Opened URL"
sleep(10)
browser.find_element_by_id('skip_button').click()
sleep(10)
browser.quit()
#print "Adding one to proxy count"
except Exception,e:
print "Skipping proxy. Error occured"
# For debugging, uncomment line below
#print str(e)
browser.quit()
run_through += 1
continue
run_through += 1
if run_through >= proxies:
print "No more proxies"
break
print 'Done!'
我得到了这个错误:
Traceback (most recent call last):
File "code.py", line 40, in <module>
chrome_options.binary_location(value = u"C:\\ProgramFiles\\Google\\Chrome\\c
hrome.exe")
TypeError: 'str' object is not callable
希望我的问题很明确。
答案 0 :(得分:5)
你正在做chrome_options.binary_location()
但是binary_location是一个字符串,而不是一个函数。
在查看the source code之后,我们似乎在这里得到了一个吸气剂和一个二传手。 @ l4mpi似乎是正确的 - 只需执行chrome_options.binary_location = "C:\\ProgramFiles\\Google\\Chrome\\chrome.exe"
即可。
您可以在此处找到Selenium文档:http://selenium-python.readthedocs.org/
旧(错)回答:
这里你可能想要的是chrome_options.setBinary("C:\\ProgramFiles\\Google\\Chrome\\chrome.exe")
,referenced in the docs。