zoukankan      html  css  js  c++  java
  • 使用 mitmdump 进行 selenium webDriver绕过网站反爬服务的方法 pdd某宝 可用

    安装:  pip install  mitmproxy

    新建一个脚本

    脚本代码:

     1 from mitmproxy import ctx
     2 
     3 injected_javascript = '''
     4 // overwrite the `languages` property to use a custom getter
     5 Object.defineProperty(navigator, "languages", {
     6   get: function() {
     7     return ["zh-CN","zh","zh-TW","en-US","en"];
     8   }
     9 });
    10 // Overwrite the `plugins` property to use a custom getter.
    11 Object.defineProperty(navigator, 'plugins', {
    12   get: () => [1, 2, 3, 4, 5],
    13 });
    14 // Pass the Webdriver test
    15 Object.defineProperty(navigator, 'webdriver', {
    16   get: () => false,
    17 });
    18 // Pass the Chrome Test.
    19 // We can mock this in as much depth as we need for the test.
    20 window.navigator.chrome = {
    21   runtime: {},
    22   // etc.
    23 };
    24 // Pass the Permissions Test.
    25 const originalQuery = window.navigator.permissions.query;
    26 window.navigator.permissions.query = (parameters) => (
    27   parameters.name === 'notifications' ?
    28     Promise.resolve({ state: Notification.permission }) :
    29     originalQuery(parameters)
    30 );
    31 '''
    32  
    33 def response(flow):
    34     # Only process 200 responses of HTML content.
    35     if not flow.response.status_code == 200:
    36         return
    37  
    38     # Inject a script tag containing the JavaScript.
    39     html = flow.response.text
    40     html = html.replace('<head>', '<head><script>%s</script>' % injected_javascript)
    41     flow.response.text = str(html)
    42     ctx.log.info('插入成功 ')
    43  

    然后运行mitmdump 

    mitmdump -s xxxx.py 

    默认为8080端口,将webDriver设置代理127.0.0.1:8080

    然后就能监听和修改selenium特征了。

  • 相关阅读:
    系统集成项目管理工程师高频考点(第一章)
    2、无重复字符的最长子串
    1、爬楼梯
    webpack起步
    Centos7安装nginx
    Centos7安装nacos
    Centos7安装java和maven
    centos7安装fastDFS
    aop中获取请求消息和属性
    数据库面对高并发的思路
  • 原文地址:https://www.cnblogs.com/dayouzi/p/12059102.html
Copyright © 2011-2022 走看看