python :在firefox上使用代理访问相关页面
在firefox上使用代理访问相关页面
1 from selenium import webdriver 2 from selenium.webdriver.firefox.options import Options 3 4 profile = webdriver.FirefoxProfile() 5 proxy = '39.137.95.74:80' 6 ip, port = proxy.split(":") 7 port = int(port) 8 # 不使用代理的协议,注释掉对应的选项即可 9 settings = { 10 'network.proxy.type': 1, # 0: 不使用代理;1: 手动配置代理 11 'network.proxy.http': ip, 12 'network.proxy.http_port': port, 13 'network.proxy.ssl': ip, # https的网站, 14 'network.proxy.ssl_port': port, 15 } 16 # 更新配置文件 17 for key, value in settings.items(): 18 profile.set_preference(key, value) 19 profile.update_preferences() 20 21 options = Options() 22 firefox = webdriver.Firefox(firefox_profile=profile, options=options) 23 firefox.get('http://www.cq-m.com.cn/wps/portal/login/!ut/p/') 24 print(firefox.page_source) 25 firefox.close() 26 firefox.quit()
活到老,学到老。

浙公网安备 33010602011771号