selenium爬虫时添加账密IP代理认证的方法

需求

selenium爬虫时需要添加IP代理,而IP代理使用的是账密认证,这时使用下面普通的添加代理方式是无法获取到请求页面

ChromeOption.add_argument("--proxy-server=http://ip:port")

需要使用以下代码,提供格式为user:password:IP_ADDRESS:port的代理即可


import os
import zipfile

from selenium import webdriver


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"
}
"""

def get_background_js(proxy_user, proxy_pass, proxy_host, proxy_port):
    print(proxy_us

猜你喜欢

转载自blog.csdn.net/zhuan_long/article/details/128536121