【selenium】无界面浏览器使用代理IP

【selenium】无界面浏览器使用代理IP

1. 代理IP的选择

无界面浏览器使用的代理IP相对于urllib,requests,scrapy使用的代理要更严格
原因在于:

  1. 无界面浏览器更换代理IP没有普通模块更换那么方便,所以代理IP的生命周期尽可能要长些
  2. 无界面浏览器会加载更多的静态资源,对代理IP的并发量有压力,所以应该选择支持并发量高的代理

所以:SOCK5是无界面浏览器的首选

2. 代码实现

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# 设置代理
chrome_options = Options()
chrome_options.add_argument('--proxy-server=http://119.114.77.174:24122') # 注意这里不能有空格

driver = webdriver.Chrome(
    executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe',
    options=chrome_options
)

driver.get('http://www.baidu.com')

猜你喜欢

转载自blog.csdn.net/kzl_knight/article/details/103187223