• selenium也能过某数、5s盾..


    文章转载于:selenium也能过某数、5s盾…

    直接安装:

    pip install undetected_chromedriver
    
    • 1

    运行代码:

    import undetected_chromedriver as uc
    import time
    
    driver = uc.Chrome(executable_path=r'C:\Users\chromedriver.exe',version_main=111)
    driver.get('网址')
    time.sleep(20)
    print(driver.page_source)
    print(driver.get_cookie())
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    神奇的地方就在源码里面:
    在这里插入图片描述

    另外一个神奇的库:

    pip install selenium-wire
    
    • 1
    from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
    import time,gzip
    
    if __name__ == '__main__':
        options = {}
        chrome_options = ChromeOptions()
        chrome_options.add_argument("--disable-gpu")
        chrome_options.add_argument("--incognito")
        chrome_options.add_argument("--disable-dev-shm-usage")
        chrome_options.add_argument("--headless")
        # chrome_options.add_argument(f"--proxy-server=http://192.168.100.24:60021")
        chrome_options.add_argument("--disable-popup-blocking")
        chrome_options.add_argument("--profile-directory=Default")
        chrome_options.add_argument("--ignore-certificate-errors")
        chrome_options.add_argument("--disable-plugins-discovery")
        chrome_options.add_argument('--no-first-run')
        chrome_options.add_argument('--no-service-autorun')
        chrome_options.add_argument('--no-default-browser-check')
        chrome_options.add_argument('--password-store=basic')
        chrome_options.add_argument('--no-sandbox')
        browser = Chrome(seleniumwire_options=options, options=chrome_options,executable_path=r'C:\Users\chromedriver.exe',version_main=111)
    
        browser.get('网址')
        time.sleep(35)
        print(browser.page_source)
        for request in browser.requests:
            if request.response:
                print(request.path)
                if 'getZxajslData' in request.path:
                # if 'shipments' in request.path:
                #     print(request.response.body)
                #获取内容为乱码可尝试用以下方法解码
                    print(gzip.decompress(request.response.body).decode("utf-8"))
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    这个库的优点就是能获取打开这个页面后,发出请求返回的结果,灰常好用
    奇怪的是这个库明明也使用了undetected_chromedriver,但是访问相同的网站却需要验证。

  • 相关阅读:
    Atcoder ABC340 C - Divide and Divide
    计算机是如何工作的(上篇)
    Vue3.2中,CSS与数据的双向绑定
    如何利用复制就好工具做英标和生词表--写给自己
    二维码制作教程分享,大家一起来学习吧!
    ASM字节码插桩:打印方法名、入参、返回值、方法耗时
    Spring-boot Mybatis-plus 实战应用
    代码面试分类刷题列表
    react使用umi-plugin-locale配置国际化
    多维时序 | MATLAB实现SSA-CNN-BiGRU-Attention多变量时间序列预测(SE注意力机制)
  • 原文地址:https://blog.csdn.net/weixin_38819889/article/details/136548825