Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51735

Re: script to Login a website

From Dave Angel <davea@davea.name>
Subject Re: script to Login a website
Date 2013-08-01 14:18 +0000
References <ece5f6b0-16da-4c3a-83d1-6340cb10cb9d@googlegroups.com> <6ad4bcae-40ba-4fd1-9b88-f0072cc17764@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.78.1375366743.1251.python-list@python.org> (permalink)

Show all headers | View raw


wachkama@gmail.com wrote:

> On Wednesday, July 31, 2013 11:33:25 AM UTC-4, wach...@gmail.com wrote:
>> I have created a script to log in a website. It gets its username and password from two files, then log's in with this credentials. My code is not showing me what username it is using to login from the file. And I am not sure if it is even opening up the url and prompting for login. I am stuck can someone help me ?
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>     import urllib, urllib2
>> 
>> 
>> 
>>     user = open ('users.txt' , 'r')
>> 
>>     password = open ('password.txt' , 'r')
>> 
>> 
>> 
>>     for users in user:
>> 
>>         password.seek(0)
>> 
>>         for pass_list in password:
>> 
>>             login_data = users + '\n' + pass_list
>> 
>>             print login_data

Please ignore myearlier post, as I somehow missed your post where you
showed the code.

Anyway, your problem is that you print the login_data, but you don't act
on it.  You should make the call to the login function right after the
print statement, rather than after the loops are done.  At that point,
all you have is the last user name and password.

All the following code should be moved to a function, and called from
the same level as the print.

>> 
>>            
>> 
>>     base_url = 'http://mysite.com'       
>> 
>>     #login action we want to post data to 
>> 
>>     response = urllib2.Request(base_url)     
>> 
>>     login_action = '/auth/login'   
>> 
>>     login_action = base_url + login_action
>> 
>>     response = urllib2.urlopen(login_action, login_data)
>> 
>>     response.read()
>> 
>>     print response.headers
>> 
>>     print response.getcode()
>
=
-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

script to Login a website wachkama@gmail.com - 2013-07-31 08:33 -0700
  Re: script to Login a website John Gordon <gordon@panix.com> - 2013-07-31 16:21 +0000
    Re: script to Login a website wachkama@gmail.com - 2013-07-31 09:50 -0700
      Re: script to Login a website Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-31 22:57 -0400
      Re: script to Login a website Dave Angel <davea@davea.name> - 2013-08-01 12:59 +0000
  Re: script to Login a website Joel Goldstick <joel.goldstick@gmail.com> - 2013-07-31 16:39 -0400
  Re: script to Login a website wachkama@gmail.com - 2013-08-01 06:48 -0700
    Re: script to Login a website Dave Angel <davea@davea.name> - 2013-08-01 14:18 +0000
  Re: script to Login a website wachkama@gmail.com - 2013-08-01 12:31 -0700

csiph-web