Python 硒刮削时如何去除积垢

Python 硒刮削时如何去除积垢,python,selenium,webdriver,screen-scraping,user-agent,Python,Selenium,Webdriver,Screen Scraping,User Agent,我试图用Selenium清理一个网站,但我认为它在很多方面阻碍了这种访问 显示的错误消息是:“selenium.common.exceptions.NoSuchWindowException:消息:浏览上下文已被丢弃”,但有时会显示一条错误,表示加载页面的时间已过 此外,Firefox在加载此页面时消耗了大量CPU和内存 我已经尝试过更改用户代理,或者直接运行它,但没有结果 代码如下: from selenium import webdriver browser = webdriver.Fire

我试图用Selenium清理一个网站,但我认为它在很多方面阻碍了这种访问

显示的错误消息是:“selenium.common.exceptions.NoSuchWindowException:消息:浏览上下文已被丢弃”,但有时会显示一条错误,表示加载页面的时间已过

此外,Firefox在加载此页面时消耗了大量CPU和内存

我已经尝试过更改用户代理,或者直接运行它,但没有结果

代码如下:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.bet365.com/#/HO/')
matches = browser.find_elements_by_class_name('him-Fixture')
browser.quit()

有没有绕过它的提示?

有时候浏览器加载太晚。因此,您在代码中添加了
time.sleep()
函数

例如:

from selenium import webdriver
import time
browser = webdriver.Firefox()
browser.get('https://www.bet365.com/#/HO/')
time.sleep(5)
matches = browser.find_elements_by_class_name('him-Fixture')
browser.quit()

若页面使用JavaScript添加/显示数据,那个么这个JavaScript需要几(毫秒)秒来完成。Selenium不知道JavaScript在做什么,也不等待JavaScript——因此您可能需要自己用
time.sleep
。或者使用我尝试过的,但现在它显示了以下错误:selenium.common.exceptions.WebDriverException:Message:Failed to decode来自木偶的响应此答案可能会帮助您: