OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I save/load specific browser cookies?

  • Thread starter Thread starter Rontron
  • Start date Start date
R

Rontron

Guest
I have the following Python code that is supposed to log into a website using the .ROBLOSECURITY cookie. It also includes an except IOERROR: function so that if the .ROBLOSECURITY cookie doesn't log in, it will use a username/password to log in AND it will save the cookies it gets from that.

Code:
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

I think that cookielib.LWPCookieJar().load("cookies.txt") is not working because it is also loading other cookies other than the .ROBLOSECURITY (Which I know logs in if you only use that). How do I either load ONLY the .ROBLOSECURITY cookie or save ONLY the .ROBLOSECURITY (So that other cookies don't interfere with the .ROBLOSECURITY logging in)?

Also, I'm not sure if my except IOError: will function correctly because I only know that that works if I change my cookielib.LWPCookieJar().load("cookies.txt") to cookielib.MozillaCookieJar().load("cookies.txt")

Lastly, how can I change my .ROBLOSECURITY's expiration date to something like 2050-12-31 24:00:00Z
<p>I have the following Python code that is supposed to log into a website using the .ROBLOSECURITY cookie. It also includes an <code>except IOERROR:</code> function so that if the .ROBLOSECURITY cookie doesn't log in, it will use a username/password to log in AND it will save the cookies it gets from that.</p>

<pre><code>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
</code></pre>

<p>I think that <code>cookielib.LWPCookieJar().load("cookies.txt")</code> is not working because it is also loading other cookies other than the .ROBLOSECURITY (Which I know logs in if you only use that). How do I either load ONLY the .ROBLOSECURITY cookie or save ONLY the .ROBLOSECURITY (So that other cookies don't interfere with the .ROBLOSECURITY logging in)? </p>

<p>Also, I'm not sure if my <code>except IOError:</code> will function correctly because I only know that that works if I change my <code>cookielib.LWPCookieJar().load("cookies.txt")</code> to <code>cookielib.MozillaCookieJar().load("cookies.txt")</code></p>

<p>Lastly, how can I change my .ROBLOSECURITY's expiration date to something like 2050-12-31 24:00:00Z</p>
 

Latest posts

O
Replies
0
Views
1
OrangeRind
O
D
Replies
0
Views
2
Domantas Giedraitis
D
Top