V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
yasea
V2EX  ›  Python

求助: selenium chrome 模拟真实请求 DHL 跟踪数据返回 Access Denied 怎么破?使用随机代理+随机 UA 仍然不行

  •  
  •   yasea · 2021-12-03 10:24:36 +08:00 · 1524 次点击
    这是一个创建于 875 天前的主题,其中的信息可能已经有所发展或是发生改变。
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--disable-gpu')# win 必须使用该选项
    chrome_options.add_argument('log-level=2')#屏蔽日志
    chrome_options.add_argument('--disable-software-rasterizer')
    chrome_options.add_argument("--disable-extensions")
    chrome_options.add_argument('--disable-logging')
    chrome_options.add_argument('--ignore-certificate-errors')
    chrome_options.add_argument('--ignore-ssl-errors')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument("--window-size=1220,800")
    chrome_options.add_argument('user-agent=' + spider_utils.get_ua())
    chrome_options.add_argument('--proxy-server={0}'.format(proxy_ip))
    prefs = {
    'profile.default_content_setting_values' : {
    'notifications' : 2
    }
    }
    chrome_options.add_experimental_option('prefs',prefs)
    前几个月是能正常工作的, 最近不好使了, 有经验的朋友,请帮忙瞅瞅
    7 条回复    2022-01-14 22:25:53 +08:00
    yasea
        1
    yasea  
    OP
       2021-12-03 11:02:44 +08:00
    补充一下,写爬虫的主要目的是对物流单号的 DHL 跟踪数据批量截图保存,因为官方只支持查询近 3 个月的数据。
    dicc
        2
    dicc  
       2021-12-03 11:57:40 +08:00
    add_argument data-dir 这个目录指向你 chrome 真实的数据目录
    yasea
        3
    yasea  
    OP
       2021-12-03 13:24:55 +08:00
    @dicc 谢谢,中午测试了下, 依然被反爬了,有时候返回 Access Denied , 有时候返回这个:
    Your tracking attempt has been blocked
    Please note that the tracking status information on this website is intended for human consumption via the website only. It is not intended to be used for integration with your systems. Automated extraction of information by bots, website scraping etc. is prohibited.
    dicc
        4
    dicc  
       2021-12-13 09:36:00 +08:00
    兄弟,试试这个思路,我用这个思路绕过了一个网站.

    https://www[.]cnblogs.com/lovealways/p/9813059.html

    相当于它在启动的时候,是以用户的方式启动.但是后续可以用程序控制
    yasea
        5
    yasea  
    OP
       2021-12-13 17:59:02 +08:00
    @dicc 谢谢啦,新思路比较有启发, 我尽快试试看
    janda
        6
    janda  
       2021-12-15 15:29:27 +08:00
    这个可以试试看
    # 禁止网站识别自动化
    chrome_options.add_argument('disable-blink-features=AutomationControlled')

    自己可以在浏览器 console 打印下:window.navigator.webdriver
    正常浏览器返回的 false 、chromedrive 的浏览器会是 true
    yasea
        7
    yasea  
    OP
       2022-01-14 22:25:53 +08:00
    @janda 谢谢老铁,也不好使, 反爬机制不太好突破了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3626 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:30 · PVG 12:30 · LAX 21:30 · JFK 00:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.