【问题标题】:Why Chrome close without close() or quit()?为什么 Chrome 在没有 close() 或 quit() 的情况下关闭?
【发布时间】:2017-03-25 22:04:27
【问题描述】:

我的 ChromeDriver 版本是 2.22

在我的代码中,没有quit()和close(),但是Chrome浏览器每次执行后都会关闭。

但如果我将 webdriver 更改为 Firefox,它运行良好。

我的代码是

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

def scrapy_list_from_youtube_list(url):
    browser = webdriver.Chrome()
    browser.get(url)

    links = browser.find_elements_by_class_name('pl-video-title-link')
    download_list = []
    for link in links:
        download_list.append(link.get_attribute('href'))
        print download_list
    i = 0
    for download_link in download_list[0:2]:
        try:
            browser.get('http://www.en.savefrom.net/')
            inout = browser.find_element_by_id('sf_url')
            inout.send_keys(download_link)
            inout.send_keys(Keys.ENTER)
            time.sleep(20)
            c = browser.find_element_by_link_text('Download')
            print i
            # print c.get_attribute('href')
            c.click()

            i = i +1
        except Exception as e:
            print e



scrapy_list_from_youtube_list('https://www.youtube.com/playlist?list=PLqjtD4kfVG7OFk0vLP1BxUJTmN3-Uj9qM')

【问题讨论】:

  • 您收到异常消息了吗?
  • 无异常信息

标签: python selenium


【解决方案1】:

我遇到了类似的问题。但我的代码中有driver.close() 行。我删除了该行,执行完成后我的 chrome 窗口没有关闭。尝试获得类似的解决方法。

【讨论】:

    猜你喜欢
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多