如何使用带有请求库的cookie在网站上注册。 使用下面的代码我无法连接。
import requests
cookie = {
"name": "xfss",
"value": "xxxxxxxxxxxxxxx",
"domain": ".uptobox.com",
"hostOnly": "",
"path": "/",
"secure": "",
"httpOnly": "",
"session": "",
"expirationDate": '1553281395',
"storeId": "firefox-private",
"firstPartyDomain": ""
}
r = requests.post("https://uptobox.com/?op=login&referer=homepage",cookies=cookie)
print(r.content)
答案 0 :(得分:0)
这是一个有效的代码:
import urllib2,urllib
UA = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'
headers = { 'User-Agent' : UA }
url = 'https://uptobox.com/'
post_data = {}
post_data['op'] = 'login'
post_data['login'] = 'LOGIN'
post_data['password'] = 'MDP'
req = urllib2.Request(url, urllib.urlencode(post_data), headers)
req.add_header('cookie', 'xfss=XXXXXXXXXXXXXXX')
response = urllib2.urlopen(req)
try:
response = urllib2.urlopen(req)
except urllib2.URLError, e:
print "debug" + str(getattr(e, "code", None))
print "debug" + str(getattr(e, "reason", None))
sHtmlContent = response.read()
head = response.headers
cookies=response.info()['Set-Cookie']
response.close()
print cookies
print head
print 'Connected ' + str('op=my_account' in sHtmlContent)
但我有一个问题:如何动态获取xfss cookie?我认为它每24小时到期