Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urllib2 data sending

Tags:

python

urllib2

I've recently written this with help from SO. Now could someone please tell me how to make it actually log onto the board. It brings up everything just in a non logged in format.

import urllib2, re
import urllib, re
logindata = urllib.urlencode({'username': 'x', 'password': 'y'})
page = urllib2.urlopen("http://www.woarl.com/board/index.php", logindata)
pagesource = page.read()
print pagesource
like image 963
user33061 Avatar asked Mar 10 '26 06:03

user33061


2 Answers

Someone recently asked the same question you're asking. If you read through the answers to that question you'll see code examples showing you how to stay logged in while browsing a site in a Python script using only stuff in the standard library.

The accepted answer might not be as useful to you as this other answer, since the accepted answer deals with a specific problem involving redirection. However, I recommend reading through all of the answers regardless.

like image 181
Eli Courtwright Avatar answered Mar 11 '26 18:03

Eli Courtwright


You probably want to look into preserving cookies from the server.

Pycurl or Mechanize will make this much easier for you

like image 38
rebra Avatar answered Mar 11 '26 19:03

rebra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!