python selenium

top啦它 2020-11-11 04:12:21
import time
import random
from fake_useragent import UserAgent
from selenium import webdriver
import random,time
import threading
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from fake_useragent import UserAgent

headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'zh-CN,zh;q=0.9',
'User-Agent': UserAgent().random,
'Connection': 'keep-alive',
}



driver_path = r"D:\迅雷下载\geckodriver-v0.27.0-win64\geckodriver.exe"

driver = webdriver.Chrome
driver = webdriver.Firefox(executable_path=driver_path,desired_capabilities=header)
#会报错

报错:

就是代码的最后一行。
如果把desired_capabilities去掉就可以正常模拟访问网站了。但是我想给它添加一些请求头,请问要怎么添加
...全文
111 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
陈年椰子 2020-11-11
  • 打赏
  • 举报
回复
错误提示说的是headers 里有key 重复。 试试只保留
headers = {
    'User-Agent': UserAgent().random,
    'Connection': 'keep-alive',
    }
成功后,再逐条加上其他KEY

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧