Selenium Chrome Configuration Proxy python edition

Source: Internet
Author: User

Environment: Windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64-bit)

Selenium official to the Firefox agent configuration is not effective, and did not see the appropriate configuration, for the chrome selenium officially did not tell how to configure, but the following two ways are valid:

1. Connect a proxy with no user name password authentication

Chromeoptions = Webdriver. Chromeoptions () chromeoptions.add_argument ('--proxy-server=http://ip:port')   = Webdriver. Chrome (chrome_options=chromeoptions)

2. Connection with user name and password

 fromSeleniumImportWebdriverdefcreate_proxyauth_extension (Proxy_host, Proxy_port, Proxy_username, Proxy_password, Scheme='http', plugin_path=None):"""Proxy Auth Extension args:proxy_host (str): domain or IP address, ie proxy.domain.com proxy_port (in T): Port Proxy_username (str): Auth username Proxy_password (str): auth password Kwargs:scheme (s TR): Proxy scheme, default HTTP Plugin_path (str): Absolute path of the extension return str-plugin _path"""    ImportstringImportZipFileifPlugin_path isNone:plugin_path='D:/webdriver/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": ["Backgro Und.js "]}," Minimum_chrome_version ":" 22.0.0 "}"""Background_js=string. Template ("""var config = {mode: "Fixed_servers", rules: {singleproxy: {SC heme: "${scheme}", Host: "${host}", Port:parseint (${port})}, Byp    Asslist: ["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)returnPlugin_pathproxyauth_plugin_path=create_proxyauth_extension (Proxy_host="proxy.crawlera.com", Proxy_port=8010, Proxy_username="Fea687a8b2d448d5a5925ef1dca2ebe9", Proxy_password="") CO=Webdriver. Chromeoptions () co.add_argument ("--start-maximized") co.add_extension (proxyauth_plugin_path) driver= Webdriver. Chrome (chrome_options=co) driver.get ("http://www.amazon.com/")

The above directly through the Python code to generate chrome required zip plug-in file, IP port user name password written on their own, the original source:

https://vimmaniac.com/blog/bangal/selenium-chrome-driver-proxy-with-authentication/

Plug-in source code Https://github.com/RobinDev/Selenium-Chrome-HTTP-Private-Proxy

Selenium Chrome Configuration Proxy python edition

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.