系统: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
原文:https://www.cnblogs.com/kindvampire/p/13492770.html