Selenium进行滑块验证时,采用了定速移动滑块,没有人为模拟,验证次数多了就不会通过,采用了Chrome,请问怎么通过?


def get_Html(url):
    """requests到url的HTML"""
    chrome_options = ChromeOptions()
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
    driver = webdriver.Chrome(options=chrome_options)
    try:
        driver.get(url)
        driver.maximize_window()
        time.sleep(1)
        source = driver.find_element_by_id('nc_1_n1z')
        action = ActionChains(driver)
        action.click_and_hold(source).perform()
        distance = 300
        tracks = get_tracks(distance)
        # for i in tracks:
        #     action.move_by_offset(xoffset=i, yoffset=0).pause(0.1).perform()
        # time.sleep(0.5)
        i = 0
        while i <= distance:
            action.move_by_offset(xoffset=60, yoffset=0).pause(0.1).perform()
            i += 60
        action.release().perform()

    finally:
        driver.get(driver.current_url)
        time.sleep(1)
    # driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")
    # driver.implicitly_wait(20)
        target = driver.find_element_by_css_selector(".footer")
        driver.execute_script("arguments[0].scrollIntoView();", target)
        source = driver.page_source
        html1 = etree.HTML(source)
    return html1

滑块验证次数多了会验证不通过,但人去拖动就没问题,window.navigator.webdriver浏览器控制台显示的是false,在网上搜了可能是Chrome浏览器驱动文件(对windows而言就是对应版本的chromedriver.exe)中的【特征字符串】被网站截获,判断出是爬虫所为。
但不知道是不是其他问题,请教一下各位同学

  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/750570
  • 除此之外, 这篇博客: Python文件编译或打包成exe文件,直接在其它Windows电脑上运行中的 4. 打包selenium脚本时集成chromedriver.exe的问题 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 采用pyinstaller 打包selenium项目时,一般需要再同级目录中添加谷歌浏览器chromedriver.exe驱动,否则会报错。在转发给其他人使用时,还要附带一个驱动,就会很不方便。通过如下方法可以解决此问题。