我有下面的Python代码,它应该使用.ROBLOSECURITY cookie登录到一个网站。它还包含一个except IOERROR:
函数,这样如果.ROBLOSECURITY cookie没有登录,它将使用用户名/密码登录,并保存从中获得的cookie。在
import urllib2
import urllib
import cookielib
try:
cookielib.LWPCookieJar().load("cookies.txt") #Trying to load the cookie file
except IOError: #In case the cookies.txt fails to log in. I don't know if IOError is the correct error specification for an expired cookie
print "Loading stored cookies failed, manually logging in..."
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib2.install_opener(opener)
authentication_url = 'https://www.roblox.com/newlogin'
payload = {
'username' : 'UsernameHere',
'password' : 'PasswordHere',
'' : 'Log In',
}
data = urllib.urlencode(payload)
req = urllib2.Request(authentication_url, data)
resp = urllib2.urlopen(req)
cj.save("cookies.txt") #Saving to the cookie file
tc = urllib2.urlopen("http://www.roblox.com/My/Money.aspx").read() #The hidden page
checksession = re.findall('My Transactions',tc) #Just checking for text that is only found on the hidden page
print checksession
我认为cookielib.LWPCookieJar().load("cookies.txt")
不起作用,因为它还加载了除.ROBLOSECURITY之外的其他cookies(如果您只使用它,我知道它会登录)。如何只加载.ROBLOSECURITY cookie或只保存.ROBLOSECURITY(以便其他cookie不会干扰.ROBLOSECURITY登录)?在
另外,我不确定我的except IOError:
是否能正常工作,因为我只知道如果我将cookielib.LWPCookieJar().load("cookies.txt")
更改为cookielib.MozillaCookieJar().load("cookies.txt")
,那么它就可以工作了
最后,我怎样才能将我的.ROBLOSECURITY的有效期改为2050-12-31 24:00:00Z
这是我最后的密码:
相关问题 更多 >
编程相关推荐