Python website logger

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Python website logger

Post by AAlexK on Mon Jul 29, 2013 7:29 am
([msg=76669]see Python website logger[/msg])

Hey everyone,
First time poster here so be nice!

I'm trying to write a little python script to log in to websites and print out the cookies for me but I've been running into troubles.
At the moment I'm trying to get it to log in to :)

Here is my script:
Code: Select all
import urllib2
import urllib
import cookielib

# Store the cookies and create an opener to hold them
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# Add our headers
opener.addheaders = [('User-agent', 'Tester')]

# Install the opener, changes the global opener to the one we just made

# URL for authentification
auth_url = ''

# Parameters to send
payload = {
   'username': 'AAlexK',
   'password': 'changethis',
   'btn_submit': 'Login'

# Encode payload
data = urllib.urlencode(payload)

# Build request object (supplying 'data' makes it a POST)
req = urllib2.Request(auth_url, data)

# Make request and store in resp
resp = urllib2.urlopen(req)

# Print out the resp from server
print resp

I actually found this code on for reddit, I tried to modify it for HTS.
From what I can see, this is the login form on the main HTS website:

Code: Select all
<form id="loginform" method="post" action="/user/login">
      <div id="innerlogin">
      <script type="text/javascript">var userclicked=0; var passclicked=0;</script>
      <p><input type="text" name="username" class="login" value="" onclick="if(userclicked==0){this.value='';userclicked=1;};" title="Username" /></p>
      <p><input type="password" name="password" class="login" value="" onclick="if(passclicked==0){this.value='';passclicked=1;};" title="Password" /></p>
            <p><input type="submit" value="Login" name="btn_submit" class="submit-button" /></p>

I see three inputs and I've put them in the right order in my script and I think I've got the right auth url.

Unfortunately I'm not getting a very nice response from the server:
Code: Select all
<addinfourl at 36515712 whose fp = <socket._fileobject object at 0x022D3DB0>>

(On a side note anyone know what that response means? AddInfoUrl ? )

Can anyone explain why my script isn't working and how I should go about to make it function properly?

Thanks for your time!
New User
New User
Posts: 1
Joined: Mon Jul 22, 2013 12:45 pm
Blog: View Blog (0)

Re: Python website logger

Post by -Ninjex- on Mon Jul 29, 2013 11:15 pm
([msg=76675]see Re: Python website logger[/msg])

To be honest, I learned python before, but I stopped coding in python right after I learned it. This has been a whiles ago, so I can't really help much. However, I noticed inside of your code you are going to need to set a referrer for Without it, you will get a bad referrer error from the hts main page.
I can look up some stuff and see if I can't get some working code for this...

Check this out
For those that know
K: 0x2CD8D4F9
User avatar
Posts: 1685
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)

Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests