from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
# 设置代理IP
proxy_ip = "your_proxy_ip"
proxy_port = "your_proxy_port"
# 设置代理
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = f"{proxy_ip}:{proxy_port}"
proxy.ssl_proxy = f"{proxy_ip}:{proxy_port}"
# 配置浏览器选项
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=http://{}:{}'.format(proxy_ip, proxy_port))
# 启动浏览器
driver = webdriver.Chrome(executable_path='path/to/chromedriver', options=chrome_options)
# 访问百度官网
driver.get('https://www.baidu.com')
# 在这里执行你的操作,比如查找元素、输入搜索关键词等
# 关闭浏览器
driver.quit()
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
# 设置代理IP
proxy_ip = "127.0.0.1"
proxy_port = "1080"
# 配置浏览器选项
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=http://{}:{}'.format(proxy_ip, proxy_port))
# 启动浏览器
chrome_service = Service("./chromedriver.exe")
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
# 访问百度官网
driver.get('https://www.baidu.com')
# 在这里执行你的操作,比如查找元素、输入搜索关键词等
time.sleep(30)
# 关闭浏览器
driver.quit()
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.proxy import Proxy, ProxyType
# 设置代理IP
proxy_ip = "your_proxy_ip"
proxy_port = "your_proxy_port"
proxy_username = "your_proxy_username"
proxy_password = "your_proxy_password"
# 设置代理
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = f"{proxy_ip}:{proxy_port}"
# 配置代理的认证信息
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
proxy_auth = f"{proxy_username}:{proxy_password}"
capabilities['proxy'] = {
'httpProxy': proxy.http_proxy,
'ftpProxy': proxy.http_proxy,
'sslProxy': proxy.http_proxy,
'proxyType': 'MANUAL',
'socksUsername': proxy_username,
'socksPassword': proxy_password
}
# 配置浏览器选项
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_argument('--proxy-server=http://{}:{}'.format(proxy_ip, proxy_port))
# 启动浏览器
chrome_service = Service("./chromedriver.exe")
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
# 访问百度官网
driver.get('https://www.baidu.com')
# 在这里执行你的操作,比如查找元素、输入搜索关键词等
time.sleep(30)
# 关闭浏览器
driver.quit()
http://api.yilian.top/v2/proxy/proxies?num=1&type=1&token=XUzBRPIdCesGx7DYyaHerdaP2XkuXk2m&format=txt]
{
"errcode": 0,
"errmsg": "获取ip地址成功,共1个",
"data": [
{
"real_ip": "182.114.35.123",
"ip": "182.114.35.123",
"prov": "河南",
"city": "三门峡",
"isp": "联通",
"proxy_user": "9ER62CtIr",
"proxy_pass": "fGGVvqedX",
"proxy_port": 10007,
"usage": "curl -x 182.114.35.123:10007 -U 9ER62CtIr:fGGVvqedX https://www.baidu.com",
"expire_time": "2023-12-31 17:49:59",
"expire_timestamp": 1704016199
}
]
}
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
def create_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 (int): port
proxy_username (str): auth username
proxy_password (str): auth password
kwargs:
scheme (str): proxy scheme, default http
plugin_path (str): absolute path of the extension
return str -> plugin_path
"""
import string
import zipfile
if plugin_path is None:
plugin_path = 'Selenium-Chrome-HTTP-Private-Proxy.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
def configure_headless_browser(proxy_config):
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
proxyauth_plugin_path = create_proxyauth_extension(
proxy_host=proxy_config[0],
proxy_port=proxy_config[1],
proxy_username=proxy_config[2],
proxy_password=proxy_config[3]
)
chrome_options.add_extension(proxyauth_plugin_path)
# chrome_options.add_argument('--headless')
# chrome_options.add_argument(
# "user-agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'")
chrome_service = Service("./chromedriver.exe")
return webdriver.Chrome(service=chrome_service, options=chrome_options)
# 设置代理IP
proxy_config = ["175.153.142.127""", "10033", "9ER62CtIr", "fGGVvqedX"]
# 启动浏览器
driver = configure_headless_browser(proxy_config)
# 访问百度官网
driver.get('https://www.baidu.com')
# 在这里执行你的操作,比如查找元素、输入搜索关键词等
time.sleep(30)
# 关闭浏览器
driver.quit()
👋 你好,我是 Lorin 洛林,一位 Java 后端技术开发者!座右铭:Technology has the power to make the world a better place.
🚀 我对技术的热情是我不断学习和分享的动力。我的博客是一个关于Java生态系统、后端开发和最新技术趋势的地方。
🧠 作为一个 Java 后端技术爱好者,我不仅热衷于探索语言的新特性和技术的深度,还热衷于分享我的见解和最佳实践。我相信知识的分享和社区合作可以帮助我们共同成长。
💡 在我的博客上,你将找到关于Java核心概念、JVM 底层技术、常用框架如Spring和Mybatis 、MySQL等数据库管理、RabbitMQ、Rocketmq等消息中间件、性能优化等内容的深入文章。我也将分享一些编程技巧和解决问题的方法,以帮助你更好地掌握Java编程。
🌐 我鼓励互动和建立社区,因此请留下你的问题、建议或主题请求,让我知道你感兴趣的内容。此外,我将分享最新的互联网和技术资讯,以确保你与技术世界的最新发展保持联系。我期待与你一起在技术之路上前进,一起探讨技术世界的无限可能性。
📖 保持关注我的博客,让我们共同追求技术卓越。