首页 > 解决方案 > 运行片刻后,无法在 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()

aw 的图像,在代码无响应 5 分钟后捕捉

标签: pythonseleniumselenium-webdriverurlbrowser

解决方案


推荐阅读