美文网首页
selenium防止反爬机制

selenium防止反爬机制

作者: 阿阿潇 | 来源:发表于2021-04-10 22:15 被阅读0次

问题:打开网页不能正常加载,服务器拒绝访问

第一部分隐藏 window.navigator.webdriver (能够正常展示网页,但selenium后续的操作依然会被识别)

···

    chrome_options = Options()
    chrome_options.add_argument(
        'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 
   Chrome/86.0.4240.75 Safari/537.36')
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")

    chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
    self.driver = webdriver.Chrome(options=chrome_options)
    with open('stealth.min.js') as f:
        js = f.read()
    self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
        "source": js
    })

···
stealth.min.js文件获取 请自行关注大佬公众号获取: 未闻Code 回复关键字:stealth

如果第一步完成后能正确使用可忽略第二部

第二部分修改chromedriver关键字

我们可以用16进制编辑器将chromedriver.exe打开,查找var key= '$cdc_asdjflasutopfhvcZLmcfl_ ',将引号中的字符替换成任意字符即可
我们在Linux中安装hexedit:
···

 yum install hexedit

···
安装完成后,运行命令,将chromedriver.exe用16进制打开
···

hexedit chromedriver.exe 

···
通过Tab键将光标定位到右侧栏,按Ctrl+S进行查找'$cdc_asdjflasutopfhvcZLmcfl_ '然后直接输入替换原有字符后替换完成按Ctrl+W保存,Ctrl+X退出。
然后就可以完美避开反爬机制了

参考文案:https://mp.weixin.qq.com/s/XOXb_XvsHqgv0MUICahjJw
https://blog.csdn.net/MICHAELKING1/article/details/108322795

相关文章

  • selenium防止反爬机制

    问题:打开网页不能正常加载,服务器拒绝访问 第一部分隐藏 window.navigator.webdriver (...

  • Selenium:反爬

    1. 反爬 有时候,我们利用 Selenium 自动化爬取某些网站时,极有可能会遭遇反爬。 实际上,我们使用默认的...

  • 爬虫基础系列urllib——构造请求头(3)

    爬虫与反爬虫 爬虫:自动获取网站数据的程序 反爬虫:使用技术手段防止爬虫程序爬取数据 反扒机制1 判断用户是否是浏...

  • 淘宝密码加密方式分析,及python实现

    上回说到《分析淘宝登陆对selenium爬虫的封杀方案,反爬虫机制的升级》、《淘宝封杀selenium的ua算法分...

  • selenium反屏蔽

    现在很多网站都加上了对Selenium的检测,来防止一些爬虫的恶意爬取。即如果检测到有人在使用Selenium打开...

  • 爬虫一些方法

    我们先来说一下selenium语法 selenium这个语法呢就是模拟用户点击可以有效率的防止反爬下面我们来介绍一...

  • 最简单的selenium+Python自动右键保存图片

    最近需要爬古籍影印版图片,但是对方网站有反爬虫,于是考虑用selenium,selenium比想象中的简单。右键的...

  • 爬虫、反爬虫与突破反爬虫

    【爬虫】批量获取网站数据 【反爬虫】防止爬虫批量获取网站数据。反爬需要人力和机器成本。反爬可能将普通用户识别为爬虫...

  • 爬虫遭遇StackPath反爬的应对之策

    遇到StackPath反爬时出现图下提示: 处理方式很简单,通过selenium获取cookie即可。 此处目标:...

  • python+selenium反爬策略

    https://intoli.com/blog/not-possible-to-block-chrome-head...

网友评论

      本文标题:selenium防止反爬机制

      本文链接:https://www.haomeiwen.com/subject/clcokltx.html