第五章 爬虫进阶(二十三) 2020-02-09

二十三、 selenium设置代理IP

 

有时候频繁爬取一些网页。服务器发现你是爬虫后会封掉你的IP地址。这时候我们可以更改代理ip。更改代理ip,不同的浏览器有不同的实现方式。这里以Chrome浏览器为例来讲解:


from selenium import webdriver

 

options = webdriver.ChromeOptions()

options.add_argument(“—proxy-server=http://110.73.2.248:8123”)

driver_path = r”D:\ProgramApp\chromedriver\chromedriver.exe”

driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)

 

driver.get(‘http://httpbin.org/ip’)


设置代理:

设置代理通过ChromeOptions来设置


示例代码:


from selenium import webdriver

 

options = webdriver.ChromeOptions()

options.add_argument("--proxy-server=http://220.175.144.84:9999")

driver=webdriver.Chrome(executable_path="E:\python\chromedriver\chromedriver.exe",chrome_options=options)

 

driver.get("http://httpbin.org/ip")



上一篇文章 第五章 爬虫进阶(二十二) 2020-02-08 地址:

https://www.jianshu.com/p/c5e67c8344b5

下一篇文章 第五章 爬虫进阶(二十四) 2020-02-10 地址:

  https://www.jianshu.com/p/f708885d4073



以上资料内容来源网络,仅供学习交流,侵删请私信我,谢谢。

你可能感兴趣的:(第五章 爬虫进阶(二十三) 2020-02-09)