新浪登录限制了错误次数···加上Cookie大批账号被封要求从Cookie池中
剔除被封的账号··· 须求利用代理···
无赖百度了大半天都以特么的啥玩意儿???结果换到了 谷歌(Google)手到擒来
分分钟化解(那么难点来了?百度除了卖假药还会干啥?)

芝麻HTTP:设置Selenium+Chrome代理,seleniumchrome

腾讯网登录限制了不当次数···加上Cookie大批判账号被封必要从Cookie池中
剔除被封的账号··· 必要利用代理···
无赖百度了大半天都以特么的啥玩意儿???结果换来了 谷歌手到擒来
分分钟化解(那么难点来了?百度除去卖假药还会干啥?)

Selenium+Chrome认证代理无法通过options处理。只好换个措施运用扩张化解

初稿地址:小白学爬虫,爬虫之设置Selenium。
(Stack Overflow 那是个好地方啊)

# -*- coding: utf-8 -*-
# @Time    : 2017/11/15 9:50
# @Author  : 哎哟卧槽
# @Site    : 
# @File    : pubilc.py
# @Software: PyCharm

import string
import zipfile

def create_proxyauth_extension(proxy_host, proxy_port,
                               proxy_username, proxy_password,
                               scheme='http', plugin_path=None):
    """代理认证插件

    args:
        proxy_host (str): 你的代理地址或者域名(str类型)
        proxy_port (int): 代理端口号(int类型)
        proxy_username (str):用户名(字符串)
        proxy_password (str): 密码 (字符串)
    kwargs:
        scheme (str): 代理方式 默认http
        plugin_path (str): 扩展的绝对路径

    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

运用办法:

from selenium import webdriver
from common.pubilc import create_proxyauth_extension

proxyauth_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)

无证西夏理:

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)

 

和讯登录限制了错误次数···加上Cookie大批判账号被封必要从库克ie池中
剔除被封的账号··· 须要…

芝麻HTTP:爬虫之设置Selenium+Chrome代理,seleniumchrome

天涯论坛登录限制了不当次数···加上Cookie大批判账号被封须求从库克ie池中
剔除被封的账号··· 要求运用代理···
无赖百度了大半天都以特么的啥玩意儿???结果换来了 谷歌手到擒来
分分钟消除(那么难题来了?百度除了卖假药还会干啥?)

Selenium+Chrome认证代理不能够因此options处理。只可以换个点子应用扩大化解

初稿地址:
(Stack Overflow 这是个好地点啊)

走你!

​
# -*- coding: utf-8 -*-
# @Time    : 2017/11/15 9:50
# @Author  : 哎哟卧槽
# @Site    : 
# @File    : pubilc.py
# @Software: PyCharm

import string
import zipfile

def create_proxyauth_extension(proxy_host, proxy_port,
                               proxy_username, proxy_password,
                               scheme='http', plugin_path=None):
    """代理认证插件

    args:
        proxy_host (str): 你的代理地址或者域名(str类型)
        proxy_port (int): 代理端口号(int类型)
        proxy_username (str):用户名(字符串)
        proxy_password (str): 密码 (字符串)
    kwargs:
        scheme (str): 代理方式 默认http
        plugin_path (str): 扩展的绝对路径

    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

​

使用格局:

​

from selenium import webdriver
from common.pubilc import create_proxyauth_extension

proxyauth_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)


​

金沙注册送58 ,无证南梁理:

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)

上述完成 So Easy

天涯论坛登录限制了错误次数···加上Cookie大批账号被封必要从Cookie池中
剔除被封的账号·…

博客园登录限制了错误次数···加上Cookie大批判账号被封要求从Cookie池中
剔除被封的账号··· 需求动用代理···
无赖百度了大半天都以特么的啥玩意儿???结果换来了 谷歌(Google)手到擒来
分分钟化解(那么难点来了?百度除去卖假药还会干啥?)

Selenium+Chrome认证代理无法因此options处理。只好换个艺术应用扩展消除

Selenium+Chrome认证代理不可能通过options处理。只可以换个点子运用扩充消除

初稿地址:
(Stack Overflow 那是个好地方啊)

原来的作品地址:
(Stack Overflow 那是个好地点啊)

# -*- coding: utf-8 -*-
# @Time    : 2017/11/15 9:50
# @Author  : 哎哟卧槽
# @Site    : 
# @File    : pubilc.py
# @Software: PyCharm

import string
import zipfile

def create_proxyauth_extension(proxy_host, proxy_port,
                               proxy_username, proxy_password,
                               scheme='http', plugin_path=None):
    """代理认证插件

    args:
        proxy_host (str): 你的代理地址或者域名(str类型)
        proxy_port (int): 代理端口号(int类型)
        proxy_username (str):用户名(字符串)
        proxy_password (str): 密码 (字符串)
    kwargs:
        scheme (str): 代理方式 默认http
        plugin_path (str): 扩展的绝对路径

    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
# -*- coding: utf-8 -*-
# @Time    : 2017/11/15 9:50
# @Author  : 哎哟卧槽
# @Site    : 
# @File    : pubilc.py
# @Software: PyCharm

import string
import zipfile

def create_proxyauth_extension(proxy_host, proxy_port,
                               proxy_username, proxy_password,
                               scheme='http', plugin_path=None):
    """代理认证插件

    args:
        proxy_host (str): 你的代理地址或者域名(str类型)
        proxy_port (int): 代理端口号(int类型)
        proxy_username (str):用户名(字符串)
        proxy_password (str): 密码 (字符串)
    kwargs:
        scheme (str): 代理方式 默认http
        plugin_path (str): 扩展的绝对路径

    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

使用办法:

利用格局:

from selenium import webdriver
from common.pubilc import create_proxyauth_extension

proxyauth_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)
from selenium import webdriver  
from common.pubilc import create_proxyauth_extension  

proxyauth_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)  

无验证代理:

无证古时候理: 

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)
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)  

 

 

相关文章

网站地图xml地图