简体   繁体   English

在 driver.quit 后调用 chromedriver 不起作用?

[英]Invoking chromedriver after driver.quit not working?

I'm trying to invoke chromedriver after quitting it in my python script:在我的 python 脚本中退出后,我试图调用 chromedriver:

#set driver options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.binary_location='/usr/bin/google-chrome-stable'
chrome_driver_binary = "/usr/bin/chromedriver"
driver = webdriver.Chrome(executable_path=chrome_driver_binary, chrome_options=chrome_options)


#Set base url 
base_url = 'https://www.example.com&page='


events = []
eventContainerBucket = []

for i in range(1,40):

    #cycle through pages in range
    driver.get(base_url + str(i))
    pageURL = base_url + str(i)

    #do some stuff............

driver.quit()


#Want to re-open chrome driver here to scrape a new url

#set driver options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.binary_location='/usr/bin/google-chrome-stable'
chrome_driver_binary = "/usr/bin/chromedriver"
driver = webdriver.Chrome(executable_path=chrome_driver_binary, chrome_options=chrome_options)


#Set base url 
base_url = 'https://www.example2.com&page='
  
events = []
eventContainerBucket = []

for i in range(1,40):

    #cycle through pages in range
    driver.get(base_url + str(i))
    pageURL = base_url + str(i)

The first part of script runs fine and driver closes, but it fails to initialize the driver again on the second url scrape ( driver.get is failing).脚本的第一部分运行良好,驱动程序关闭,但在第二次 url 抓取时无法再次初始化驱动程序( driver.get失败)。 It gives me the error:它给了我错误:

Traceback (most recent call last):
  File "scraper.py", line 462, in <module>
    driver.get(base_url + str(i))
TypeError: 'WebElement' object is not callable

How can I fix this?我怎样才能解决这个问题? Thanks.谢谢。

driver.quit() causes the loss of the driver instance. driver.quit()导致driver实例丢失。
In order to use driver again fe by driver.get command you will have to have to reinitialize it with为了通过driver.get命令再次使用driver fe,您必须重新初始化它

driver = webdriver.Chrome(executable_path=chrome_driver_binary, chrome_options=chrome_options)

See here for reference.请参阅此处以供参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium ChromeDriver-driver.quit()上的HTTP 407 - Selenium ChromeDriver - HTTP 407 on driver.quit() driver.quit() 在未处理的异常之后 - driver.quit() after unhandled exception 在所有情况下调用 driver.quit() - invoke driver.quit() in all cases 硒3.0.2中的driver.quit firefox 50.1.0 firefox已停止工作 - driver.quit in selenium 3.0.2 firefox 50.1.0 firefox has stopped working 尽管使用了driver.close()和driver.quit(),为什么Chrome.exe和chromedriver.exe仍会出现在计算机的内存中? - Why do Chrome.exe and chromedriver.exe still appear in the computer's memory, despite using driver.close() and driver.quit()? python selenium driver.quit() 里面除了块 - python selenium driver.quit() inside except block python selenium driver.quit() 不会中途终止程序 - python selenium driver.quit() won't terminate the program midway 如果设置了firefox_profile,则python selenium driver.quit()无法退出firefox浏览器 - python selenium driver.quit() can not quit firefox browser if firefox_profile setted Selenium 中的 driver.quit():ConnectionRefusedError 如果用于多个驱动程序 object - driver.quit() in Selenium : ConnectionRefusedError if used on more than one driver object 尽管 driver.close 和 driver.quit,IDLE 不会终止我的 selenium 浏览器 - IDLE doesn't terminate my selenium broswer despite driver.close and driver.quit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM