首页 > 其他 > 详细

selenium——mitmproxy过检测

时间:2020-08-12 21:24:48      阅读:297      评论:0      收藏:0      [点我收藏+]

系统:ubuntu 16.04

安装:

sudo pip3 install mitmproxy

配置:

技术分享图片

 技术分享图片

 技术分享图片

 技术分享图片

 技术分享图片

配置代理:

技术分享图片

 技术分享图片

过检测脚本:

from mitmproxy import ctx

injected_javascript = ‘‘‘
// overwrite the `languages` property to use a custom getter
Object.defineProperty(navigator, "languages", {
  get: function() {
    return ["zh-CN","zh","zh-TW","en-US","en"];
  }
});

// Overwrite the `plugins` property to use a custom getter.
Object.defineProperty(navigator, ‘plugins‘, {
  get: () => [1, 2, 3, 4, 5],
});

// Pass the Webdriver test
Object.defineProperty(navigator, ‘webdriver‘, {
  get: () => false,
});


// Pass the Chrome Test.
// We can mock this in as much depth as we need for the test.
window.navigator.chrome = {
  runtime: {},
  // etc.
};

// Pass the Permissions Test.
const originalQuery = window.navigator.permissions.query;
window.navigator.permissions.query = (parameters) => (
  parameters.name === ‘notifications‘ ?
    Promise.resolve({ state: Notification.permission }) :
    originalQuery(parameters)
);
‘‘‘


def response(flow):
    # Only process 200 responses of HTML content.
    if not flow.response.status_code == 200:
        return

    # Inject a script tag containing the JavaScript.
    html = flow.response.text
    html = html.replace(<head>, <head><script>%s</script> % injected_javascript)
    flow.response.text = str(html)
    ctx.log.info(>>>> js代码插入成功 <<<<)

启动脚本:

mitmdump -s mitm.py

selenium启动:

from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

# _____________________基本设定___________________________
PROXY = "http://127.0.0.1:8080"
# _____________________启动参数___________________________
options = webdriver.ChromeOptions()
# options.add_argument(‘--headless‘)
options.add_argument(--disable-gpu)
options.add_argument("window-size=1024,768")
options.add_argument("--no-sandbox")

# _____________________代理参数___________________________
desired_capabilities = options.to_capabilities()
desired_capabilities[acceptSslCerts] = True
desired_capabilities[acceptInsecureCerts] = True
desired_capabilities[proxy] = {
    "httpProxy": PROXY,
    "ftpProxy": PROXY,
    "sslProxy": PROXY,
    "noProxy": None,
    "proxyType": "MANUAL",
    "class": "org.openqa.selenium.Proxy",
    "autodetect": False,
}
# _____________________启动浏览器___________________________
driver = webdriver.Chrome(
    chrome_options=options,
    desired_capabilities=desired_capabilities,
    executable_path=./chromedriver
)

# for i in range(1):
url  = https://account.cnblogs.com/signin
driver.get(url)
contant = driver.page_source
input("........!!!")
driver.close()

结果:

技术分享图片

 

 

 代码来自:http://www.caneman.cn/?p=767

 

selenium——mitmproxy过检测

原文:https://www.cnblogs.com/kindvampire/p/13492770.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!