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


Groups > comp.lang.python > #67542

Re: Iterate through a list and try log in to a website with urllib and re

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Iterate through a list and try log in to a website with urllib and re
Date 2014-03-03 08:47 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-435B9C.08471603032014@news.panix.com> (permalink)
References <fc7c1c7d-7811-4e58-a999-1f2e9b297cd3@googlegroups.com>

Show all headers | View raw


In article <fc7c1c7d-7811-4e58-a999-1f2e9b297cd3@googlegroups.com>,
 Marcus <marcuscvj@gmail.com> wrote:
 
> I'm trying to use urllib and urllib2 to open an url + login_data in a for 
> loop.

Step 1: Ignore all that crap and get http://www.python-requests.org/

> How can I display when successfully logged in and how to show when the 
> login is denied? 
> 
> I've tried use this:
> 
> html_content = urllib2.urlopen(url).read()
> re.findall('ERROR: The password you entered for the username USER is 
> incorrect.', html_content)

In the ideal case, whatever you're talking to will return a success or 
failure indication in the HTTP status code.

Lacking that, it will at least return something intended to be parsed 
(like JSON).

Lacking that (and, unfortunately, common), you're reduced to 
screen-scraping.  But, if you've got to do that, at least use a tool 
like lxml or BeautifulSoup to parse the HTML.

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


Thread

Iterate through a list and try log in to a website with urllib and re Marcus <marcuscvj@gmail.com> - 2014-03-03 04:32 -0800
  Re: Iterate through a list and try log in to a website with urllib and re Marcus <marcuscvj@gmail.com> - 2014-03-03 04:35 -0800
    Re: Iterate through a list and try log in to a website with urllib and re Chris Angelico <rosuav@gmail.com> - 2014-03-03 23:44 +1100
    Re: Iterate through a list and try log in to a website with urllib and re Chris Angelico <rosuav@gmail.com> - 2014-03-03 23:45 +1100
      Re: Iterate through a list and try log in to a website with urllib and re Marcus <marcuscvj@gmail.com> - 2014-03-03 04:51 -0800
        Re: Iterate through a list and try log in to a website with urllib and re Chris Angelico <rosuav@gmail.com> - 2014-03-04 00:00 +1100
          Re: Iterate through a list and try log in to a website with urllib and re Marcus <marcuscvj@gmail.com> - 2014-03-03 05:05 -0800
    Re: Iterate through a list and try log in to a website with urllib and re Chris Angelico <rosuav@gmail.com> - 2014-03-03 23:44 +1100
  Re: Iterate through a list and try log in to a website with urllib and re Roy Smith <roy@panix.com> - 2014-03-03 08:47 -0500

csiph-web