python - selenium.common.exceptions.WebDriverException:消息:未知错误:DevToolsActivePort 文件不存在
问题描述
我在 Ubuntu 上的 Python 脚本中使用 Selenium/Webdriver。下面的代码在 for 循环中通过大约 25 次迭代成功,然后得到错误:
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
我研究了这个问题,并确保我遵循了更新 Chromedriver 和 Google Chrome 的建议,并在 Chrome 选项中添加了 disable-dev-usage 参数。这是完整的代码:
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1420,1080')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument("--disable-notifications")
options.add_experimental_option('useAutomationExtension', False)
options.binary_location='/usr/bin/google-chrome-stable'
chrome_driver_binary = "/usr/bin/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
# Get base url
base_url = 'https://www.bandsintown.com/?place_id=ChIJOwg_06VPwokRYv534QaPC8g&page='
events = []
eventContainerBucket = []
for i in range(1,55):
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
#cycle through pages in range
driver.get(base_url + str(i))
pageURL = base_url + str(i)
print(pageURL)
# get events links
event_list = driver.find_elements_by_css_selector('div[class^=_3buUBPWBhUz9KBQqgXm-gf] a[class^=_3UX9sLQPbNUbfbaigy35li]')
# collect href attribute of events in even_list
events.extend(list(event.get_attribute("href") for event in event_list))
driver.close()
# iterate through all events and open them.
item = {}
allEvents = []
for event in events:
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
driver.get(event)
#Do some things here
driver.close()
Chrome驱动程序版本:
ChromeDriver 80.0.3987.149 (5f4eb224680e5d7dca88504586e9fd951840cac6-refs/branch-heads/3987_137@{#16})
谷歌浏览器稳定版:
Google Chrome 80.0.3987.149
接下来我可以尝试什么?
解决方案
推荐阅读
- python - 如何在 pandas loc 过滤条件中传递“Take All”参数?
- java - Eclipse:必须声明元素类型“上下文”
- amazon-web-services - 什么可以在“固定”时间阻止我的码头流程?
- python - 使用 Python 在 JSON 文件中的数组中添加键
- python-2.7 - 为什么在 trigger_dag 之后任务在 Airflow 1.10.2 中停留在 None 状态
- java - InputStreamReader 只返回一半的 html 文档
- animation - 如何使用“维度”在地理服务器中制作动画
- android - 将应用程序升级到 64 位 Apk anaylzer 后,lib 中只有 32 位
- java - kafka消费者收到一条之前消费过的消息
- php - php过滤器多维数组