@retry(5)
def page_driver(url):
proxies = requests.get("proxy_API").json()["ip"]
# 设置代理
profile = webdriver.FirefoxProfile()
proxy = proxies["http"].replace("http://", "")
ip, port = proxy.split(":")
port = int(port)
settings = {
'network.proxy.type': 1, # 开启“手动设置代理”
'network.proxy.http': ip, # 第三步:设置代理IP
'network.proxy.http_port': port, # 设置代理端口,注意端
}
for k, v in settings.items():
profile.set_preference(k, v)
profile.update_preferences()
options = Options()
options.add_argument('--headless') # 无界面模式
options.log.level = "fatal" # 日志等级
driver = Firefox(
executable_path=r'C:\Users\Administrator\Desktop\Firefox\geckodriver.exe',
options=options,
)
driver.get(url=url)
time.sleep(0.9)
if driver.current_url != url:
raise Exception
return driver
python3.6 + selenium3.11.0 + firfox56.0 + geckodriver0.20,参考文章selenium环境搭建。
Windows10和centos7环境下如何不生成geckodriver.log文件。欢迎知道的大佬留言