Sesame HTTP: Selenium + Chrome proxy, seleniumchrome

Source: Internet
Author: User

Sesame HTTP: Selenium + Chrome proxy, seleniumchrome

Weibo login limit the number of errors · a large number of accounts with cookies should be removed from the Cookie pool. · proxy is required. · What is the special feature of rogue Baidu for more than half a day? what are things ??? The result is solved in minutes by Google's hand? What else will Baidu do in addition to selling fake medicines ?)

Selenium + Chrome Authentication Proxy cannot be processed through options. You can only use extensions in another way.

Https://stackoverflow.com/questions/29983106/how-can-i-set-proxy-with-authentication-in-selenium-chrome-web-driver-using-pyth#answer-30953780 (Stack Overflow this is a good place)

#-*-Coding: UTF-8-*-# @ Time: interval /11/15 # @ Author: # @ Site: # @ File: pubilc. py # @ Software: PyCharmimport stringimport zipfiledef create_proxyauth_extension (proxy_host, proxy_port, proxy_username, proxy_password, scheme = 'http', plugin_path = None): "" proxy authentication plugin args: proxy_host (str): Your proxy address or domain name (str type) proxy_port (int): proxy port number (int type) proxy_username (str): User Name (string) proxy_password (str ): password (string) kwargs: scheme (str): proxy method default http plugin_path (str): Extended absolute path return str-> plugin_path "if plugin_path is None: plugin_path = 'vimm_chrome_proxyauth_plugin.zip 'manifest_json = "" {"version": "1.0.0", "manifest_version": 2, "name": "Chrome Proxy", "permissions ": ["proxy", "tabs", "unlimitedStorage", "storage", "<all_urls>", "webRequest", "webRequestBlocking"], "background ": {"scripts": ["background. js "]}," minimum_chrome_version ":" 22.0.0 "}" "background_js = string. template ("var config = {mode:" fixed_servers ", rules: {singleProxy: {scheme:" $ {scheme} ", host:" $ {host }", port: parseInt ($ {port})}, bypassList: ["foobar.com"]}; chrome. proxy. settings. set ({value: config, scope: "regular"}, function () {}); function callbackFn (details) {return {authCredentials: {username: "$ {username}", password: "$ {password}" }};} chrome. webRequest. onAuthRequired. addListener (callbackFn, {urls: ["<all_urls>"]}, ['blocking']); "). substitute (host = proxy_host, port = proxy_port, username = proxy_username, password = proxy_password, scheme = scheme,) with zipfile. zipFile (plugin_path, 'w') as zp: zp. writestr ("manifest. json ", manifest_json) zp. writestr ("background. js ", background_js) return plugin_path

Usage:

from selenium import webdriverfrom common.pubilc import create_proxyauth_extensionproxyauth_plugin_path = create_proxyauth_extension(    proxy_host="XXXXX.com",    proxy_port=9020,    proxy_username="XXXXXXX",    proxy_password="XXXXXXX")co = webdriver.ChromeOptions()# co.add_argument("--start-maximized")co.add_extension(proxyauth_plugin_path)driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", chrome_options=co)driver.get("http://ip138.com/")print(driver.page_source)

No Authentication Proxy:

options = webdriver.ChromeOptions()options.add_argument('--proxy-server=http://ip:port')  driver = webdriver.Chrome(executable_path="C:\chromedriver.exe", chrome_options=0ptions)driver.get("http://ip138.com/")print(driver.page_source)

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.