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
asus10tu
V2EX  ›  Python

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

  •  
  •   asus10tu · 2019-08-04 16:36:39 +08:00 · 6746 次点击
    这是一个创建于 1719 天前的主题,其中的信息可能已经有所发展或是发生改变。
    原本普通地用 selenium 打开网站,所有图片都会 400 请求失败的,开启开发者模式后都能正常使用了。

    但是问题来了

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

    求大佬一个思路、
    17 条回复    2019-08-07 17:33:14 +08:00
    spotfg
        1
    spotfg  
       2019-08-04 16:51:47 +08:00
    selenium 爬虫也是可以被检测到的,你可以用 mitmproxy 修改一下 driver
    Abbeyok
        2
    Abbeyok  
       2019-08-04 16:53:54 +08:00 via Android
    firefox 可以解决
    asus10tu
        3
    asus10tu  
    OP
       2019-08-04 17:14:18 +08:00
    @spotfg 我在代码里开启了开发者模式 options.add_experimental_option('excludeSwitches', ['enable-automation'])
    理论上检测 driver 之类的都跟正常浏览器一样了
    asus10tu
        4
    asus10tu  
    OP
       2019-08-04 17:14:33 +08:00
    @Abbeyok firefox 貌似无法开启开发者模式
    DanielGuo
        5
    DanielGuo  
       2019-08-04 17:20:05 +08:00
    没有遇到过你的问题,我用通过 java 或者 python 调用 selenium 做爬虫的时候,和人手工点击完全一致
    zeroDev
        6
    zeroDev  
       2019-08-04 17:24:02 +08:00 via Android
    @asus10tu Firefox 可以用的,你可以试试
    asus10tu
        7
    asus10tu  
    OP
       2019-08-04 17:47:14 +08:00
    @zeroDev 喔喔,换了 firefox 后还真全部问题都解决了,感谢,想问下是什么原理呢
    spotfg
        8
    spotfg  
       2019-08-04 17:52:12 +08:00
    那你可以试试打开 chrome 远程调试模式。实在不行,那还是乖乖用拦截修改吧
    Leigg
        9
    Leigg  
       2019-08-04 17:52:31 +08:00 via Android
    不要用 click 方法,用 execute_script 方法传入 js 代码点击元素
    asus10tu
        10
    asus10tu  
    OP
       2019-08-04 17:59:09 +08:00
    @Leigg execute_script 来触发按钮当时也试过了,不行。。
    asus10tu
        11
    asus10tu  
    OP
       2019-08-04 18:26:43 +08:00
    @spotfg 想问下远程调试模式的用意是?看看别的机子是否正常运行么
    spotfg
        12
    spotfg  
       2019-08-04 19:10:31 +08:00
    @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  
       2019-08-04 19:11:48 +08:00
    @asus10tu 如果不想太过于改动项目,可以试试这个方法,不行在换浏览器呗
    asus10tu
        14
    asus10tu  
    OP
       2019-08-04 21:10:06 +08:00
    @spotfg 原来如此,学到了。不过明明这样方法确实是把指纹都隐藏掉了,却还是不行,而且跟没开开发者模式的效果一样,实在不明白。
    lawler
        15
    lawler  
       2019-08-05 00:30:21 +08:00
    猜测是没查询到鼠标轨迹吧。
    xxxy
        16
    xxxy  
       2019-08-05 07:47:48 +08:00 via Android
    最近在用 puppeteer 写爬虫,不妨发个链接我试试
    LUXiaobo
        17
    LUXiaobo  
       2019-08-07 17:33:14 +08:00
    网站会检测 chrome 的一些属性,比如 navigator.webdriver
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2737 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.