1XBET保存COOKIES问题

1XBET无法用SELENIUM通过图片验证,我手动把COOKIES复制下来,保存成TXT,但是在调用的时候出现错误

import json,time
# 保存cookies
cookie ='xxxx'
print(cookie)

cookies={}
for line in cookie.split(";"):
    name,value = line.strip().split("=",1)
    cookies[name]=value
print(cookies)


with open('1xbet_cookies.txt','w') as f:
    f.write(json.dumps(cookies))
    f.close()

调用COOKIES

from selenium import webdriver
import json,time

url = 'https://1xbet.com/en/'
driver = webdriver.Chrome()
driver.get(url)
driver.maximize_window()
driver.implicitly_wait(30)
# 使用COOKIES登录
driver.delete_all_cookies()
f1 = open('1xbet_cookies.txt')
cookie = json.loads(f1.read())
f1.close()
for c in cookie:
    driver.add_cookie(c)
driver.refresh()

错误信息

E:\python\python.exe C:/Users/Administrator/PycharmProjects/untitled/test/1xbet_crawl.py
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/untitled/test/1xbet_crawl.py", line 15, in <module>
    driver.add_cookie(c)
  File "E:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 894, in add_cookie
    self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
  File "E:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "E:\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie'
  (Session info: chrome=75.0.3770.142)


Process finished with exit code 1

解决办法:

from selenium.webdriver import ChromeOptions

option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])


url = 'https://1xbet.com/en/'
driver = webdriver.Chrome(options=option)

使用上面的代码后,打开CHROME的开发者模式,可以解决反爬的问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值