admin管理员组文章数量:1279176
I'm trying to login into / with cookies using curl_cffi in python, but it doesn't work.
I can manually use the cookies to login by using anti detect browsers like "Dolphin Anty" and cookie editor extension.
How can I achieve this in python using requests or curl_cffi without using selenium or playwright?
My code:
from curl_cffi import requests
import os
def checkCookie(cookie):
cookie_path = os.path.join("input", cookie)
with open(cookie_path, 'r', encoding='utf-8') as f:
read_cookie = f.read()
cookies = {}
for line in read_cookie.splitlines():
parts = line.strip().split('\t')
if len(parts) >= 7:
domain, _, path, secure, expires, name, value = parts[:7]
cookies[name] = value
session = requests.Session()
session.cookies.update(cookies)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
'Accept-Language': 'en-IN,en;q=0.9',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'sec-ch-ua': '"Not A(Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Referer': '/',
'Origin': '',
}
response = session.get("/", headers=headers, impersonate="chrome", timeout=30, verify=True)
if "youraccount_steamid" in response.text:
print("Logged in")
else:
print("Failed")
with open('test.html', 'w', encoding='utf-8') as f:
f.write(response.text)
checkCookie("cookie.txt")
本文标签: pythonAuthenticating with cookies using requests or curlcffi in site doesn39t workStack Overflow
版权声明:本文标题:python - Authenticating with cookies using requests or curl_cffi in site doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741276332a2369748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论