python - 运行片刻后,无法在 selenium python 中运行此 url,显示“aw,snap”
问题描述
我希望你做得很好,运行这个网站后我得到了一个错误,看图片,在谷歌搜索了一些解决方案后,该网站在普通浏览器中运行良好,也许它阻止了 selenium 所以,我向浏览器添加了一些参数(如你所见在代码中)但没有变化,我想知道我是否可以让程序也像普通浏览器一样运行,我尝试使用 selenium ide 运行该站点(适用于普通浏览器)并且它可以工作,但我需要获取文本而不是按钮单击, 有什么想法吗?告诉我!
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
def get_countries():
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument("start-maximized")
options.add_argument("user-data-dir=C:\\Users\\viber\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("--disable-blink-features")
options.add_argument('--disable-dev-shm-usage')
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source":
"const newProto = navigator.__proto__;"
"delete newProto.webdriver;"
"navigator.__proto__ = newProto;"
})
driver.execute_cdp_cmd('Network.setUserAgentOverride', {
"userAgent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'})
driver.get("https://www.bet365.es/#/AS/B2/")
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.CLASS_NAME, "rsm-MarketGroupButton_Text")))
countries = driver.find_elements_by_class_name("rsm-MarketGroupButton_Text")
for country in countries:
print(country.text)
driver.quit()
if __name__ == '__main__':
get_countries()
解决方案
推荐阅读
- python-3.x - 如何处理由于数据延迟上传数月而导致URL不断修改的网站的数据捕获?
- canvas - 如何使用 JSPDF 将 pdf 保存到文件夹?
- android - 在 RecyclerView 中为视图的折叠和展开设置动画的问题
- python - 遍历数据框并根据列值执行代码
- elasticsearch - 使用 Elasticsearch LTR 插件构建用户个性化
- ip - tor 不尊重 MaxCircuitDirtiness
- android - 为什么旋转屏幕时 ViewModel 对象没有被破坏?
- git - git-filter-repo 没有读取我的邮件映射文件
- angular - 关闭最后一个选项卡后重定向到注销链接
- angular - 安装节点包时出错