使用 mitmdump 进行 selenium webDriver绕过网站反爬服务的方法 pdd某宝 可用

Posted 一个大柚子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 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特征了。

以上是关于使用 mitmdump 进行 selenium webDriver绕过网站反爬服务的方法 pdd某宝 可用的主要内容,如果未能解决你的问题,请参考以下文章

Python爬虫编程思想(124):抓取移动App数据--mitmdump与Python对接

Python爬虫编程思想(124):抓取移动App数据--mitmdump与Python对接

Python爬虫入门教程 48-100 使用mitmdump抓取手机惠农APP-手机APP爬虫部分

App爬虫神器mitmproxy和mitmdump的使用

python mitmdump抓包与redis订阅消息

python 启动 mitmdump