Iterate through a list and try log in to a website with urllib and re
Roy Smith
roy at panix.com
Mon Mar 3 08:47:16 EST 2014
In article <fc7c1c7d-7811-4e58-a999-1f2e9b297cd3 at googlegroups.com>,
Marcus <marcuscvj at 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.
More information about the Python-list
mailing list