python3使用selenium並加代理訪問網頁

用selenium打開瀏覽器,會遇到一個問題,打開太多容易被封IP。那麼需要一些代理來間接地取得網頁內容。

python裏面就是這一個好處,API提供這個選項。注意server後面直接跟隨代理和端口

firefox_options.add_argument("--proxy-server=http://122.141.74.186:8080")

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import sys

firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument("--proxy-server=http://122.141.74.186:8080")
binary = FirefoxBinary('C:\\Program Files\\Firefox51\\firefox.exe', log_file=sys.stdout)
driver = webdriver.Firefox(firefox_binary=binary, firefox_options=firefox_options)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章