login to https (newbie)

B

bkamrani

Hi Python gurus!
Please help me how I can login to this page:

https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/Default.aspx

I tried these two codes, but I don't seem to be successfull at all.
(Both gave same result.)
Many many thanks,
/Ben


-----------
import urllib2,urllib,cookielib
urll = "https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/
Default.aspx"
cj = cookielib.CookieJar()
opener = urllib2.build_opener( urllib2.HTTPCookieProcessor(cj))
data = urllib.urlencode ( { "username" : "myuser" ,
"password" :"mypass" } )
fp = opener.open( urll,data )
print fp.read()
------------
OR th second code
------------
import urllib2 as __urllib2
import base64 as __base64
#--------------------------------------------------------------
def download_file(url, webuser = None, webpass = None):
request = __urllib2.Request(url)

if webuser:
base64string = __base64.encodestring('%s:%s' % (webuser,
webpass))[:-1]
request.add_header("Authorization", "Basic %s" % base64string)

htmlFile = __urllib2.urlopen(request)
htmlData = htmlFile.read()
htmlFile.close()

return htmlData
#--------------------------------------------------------------
if __name__ == "__main__":
# Test
#*****************************
__url = "https://www.boplats.se/user/login_hs.aspx?ReturnUrl=/HSS/
Default.aspx"
__webuser = "myuser"
__webpass = "mypass"
print download_file(__url, __webuser, __webpass)
#*****************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top