Home » Uncategorized » 火狐浏览器 selenium 代理 改User-Agent 【python】

火狐浏览器 selenium 代理 改User-Agent 【python】

#火狐浏览器 selenium 代理http/https/sock 改User-Agent

#conding=utf-8
from selenium import webdriver
import RandomHeaders
proxies = [{"ip": '104.144.1.00', "port": '3190'}, {"ip": '104.144.45.91', "port": '3190'}]
proxy={"ip": '119.101.113.223', "port": '9999'}
proxyh={"ip": '119.101.116.114', "port": '9999'}
proxys={"ip": '119.101.117.205', "port": '9999'}
proxyk={"ip": '119.101.113.223', "port": '9999'}
ua={'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.2 (KHTML'}
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", RandomHeaders.LoadHeader()["User-Agent"])
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", str(proxyh['ip']))
profile.set_preference("network.proxy.http_port", int(proxyh['port']))
profile.set_preference("network.proxy.ssl", str(proxys['ip']))
profile.set_preference("network.proxy.ssl_port", int(int(proxys['port'])))
profile.set_preference('network.proxy.socks', str(proxy['ip']))
profile.set_preference('network.proxy.socks_port', int(int(proxy['port'])))
profile.update_preferences()
drivers = webdriver.Firefox(firefox_profile=profile)
#############################################################################
# url = 'http://132.232.249.247:81/ip'
url = 'https://www.xicidaili.com/'
drivers.get(url)
print(drivers.page_source)