推荐学习书目
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
asus10tu
V2EX  ›  Python

一个 selenium 开启开发者模式仍然被反爬的问题

  •  
  •   asus10tu · Aug 4, 2019 · 7815 views
    This topic created in 2508 days ago, the information mentioned may be changed or developed.
    原本普通地用 selenium 打开网站,所有图片都会 400 请求失败的,开启开发者模式后都能正常使用了。

    但是问题来了

    我用鼠标去打开页面中的其他链接,依然可以正常使用,但是用代码去 click 打开链接,网页就 400 错误请求了,用 pyautogui 这个鼠标点击类,也是会这样。我尝试晃动鼠标然后用代码点击还是如此,甚至我换了框架,用 pyppeteer 去操作,依然会这样。

    求大佬一个思路、
    17 replies    2019-08-07 17:33:14 +08:00
    spotfg
        1
    spotfg  
       Aug 4, 2019
    selenium 爬虫也是可以被检测到的,你可以用 mitmproxy 修改一下 driver
    Ct5T66PVR1bW7b2z
        2
    Ct5T66PVR1bW7b2z  
       Aug 4, 2019 via Android
    firefox 可以解决
    asus10tu
        3
    asus10tu  
    OP
       Aug 4, 2019
    @spotfg 我在代码里开启了开发者模式 options.add_experimental_option('excludeSwitches', ['enable-automation'])
    理论上检测 driver 之类的都跟正常浏览器一样了
    asus10tu
        4
    asus10tu  
    OP
       Aug 4, 2019
    @Abbeyok firefox 貌似无法开启开发者模式
    DanielGuo
        5
    DanielGuo  
       Aug 4, 2019
    没有遇到过你的问题,我用通过 java 或者 python 调用 selenium 做爬虫的时候,和人手工点击完全一致
    zeroDev
        6
    zeroDev  
       Aug 4, 2019 via Android
    @asus10tu Firefox 可以用的,你可以试试
    asus10tu
        7
    asus10tu  
    OP
       Aug 4, 2019
    @zeroDev 喔喔,换了 firefox 后还真全部问题都解决了,感谢,想问下是什么原理呢
    spotfg
        8
    spotfg  
       Aug 4, 2019
    那你可以试试打开 chrome 远程调试模式。实在不行,那还是乖乖用拦截修改吧
    Leigg
        9
    Leigg  
       Aug 4, 2019 via Android
    不要用 click 方法,用 execute_script 方法传入 js 代码点击元素
    asus10tu
        10
    asus10tu  
    OP
       Aug 4, 2019
    @Leigg execute_script 来触发按钮当时也试过了,不行。。
    asus10tu
        11
    asus10tu  
    OP
       Aug 4, 2019
    @spotfg 想问下远程调试模式的用意是?看看别的机子是否正常运行么
    spotfg
        12
    spotfg  
       Aug 4, 2019
    @asus10tu 不是,是为了反爬,这样可以隐藏 selenium 指纹信息。在 cmd 下输入
    chrome.exe --remote-debugging-port=9222 --user-data-dir="绝对路径"

    然后添加 chrome_options.add_experimental_option('debuggerAddress','127.0.0.1:9222')
    spotfg
        13
    spotfg  
       Aug 4, 2019
    @asus10tu 如果不想太过于改动项目,可以试试这个方法,不行在换浏览器呗
    asus10tu
        14
    asus10tu  
    OP
       Aug 4, 2019
    @spotfg 原来如此,学到了。不过明明这样方法确实是把指纹都隐藏掉了,却还是不行,而且跟没开开发者模式的效果一样,实在不明白。
    lawler
        15
    lawler  
       Aug 5, 2019
    猜测是没查询到鼠标轨迹吧。
    xxxy
        16
    xxxy  
       Aug 5, 2019 via Android
    最近在用 puppeteer 写爬虫,不妨发个链接我试试
    LUXiaobo
        17
    LUXiaobo  
       Aug 7, 2019
    网站会检测 chrome 的一些属性,比如 navigator.webdriver
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4928 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 09:45 · PVG 17:45 · LAX 02:45 · JFK 05:45
    ♥ Do have faith in what you're doing.