I hope everyone are well. I'm a new in python and itry alot to run this code but i can't understand what is the problem and how i can solve this.
My code is:
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!'
And i get this error:
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
Hope my questions is clear.
You're doing chrome_options.binary_location() but binary_location is a string, not a function.
After looking over the source code, it appears that we've just got a getter and a setter here. @l4mpi appears to be correct - simply doing chrome_options.binary_location = "C:\\ProgramFiles\\Google\\Chrome\\chrome.exe" ought to work.
You can find the Selenium docs here: http://selenium-python.readthedocs.org/
Old (wrong) answer:
What you probably wanted here was chrome_options.setBinary("C:\\ProgramFiles\\Google\\Chrome\\chrome.exe"), as referenced in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With