Log in using python and open a browser login site

I am learning how to login to a site using python via site and apply it on my site. So that I can open the web page without any login requirements. It does not show any errors, but I can not do what I want. Let the way that I do it is not a way to do it, and then please answer how to achieve it. I want to log in through the credentials that I gave, and then open the browser. However, when the page loads, it is still not logged in. Hope what I meant was clear. Please ask me if my question is cleared. We will be very grateful. Thanks!

I changed the goal a bit:

import urllib, urllib2, cookielib
import webbrowser
#cookie storage
cj = cookielib.CookieJar()
#create an opener
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#Add useragent, sites don't like to interact programs.
opener.addheaders.append(('User-agent', 'Mozilla/4.0'))
opener.addheaders.append( ('Referer', 'http://somesite.com/adminpanel/index.php') )
#encode the login data. This will vary from site to site.
#View the sites source code
#Example###############################################
#<form id='loginform' method='post' action='index.php'>
#<div style="text-align: center;">
#Username<br />
#<input type='text' name='admin_userid' class='textbox' style='width:100px' /><br />
#Password<br />
#<input type='password' name='admin_password' class='textbox' style='width:100px' /><br />
#<input type='checkbox' name='remember_me' value='y' />Remember Me<br /><br />
#<input type='submit' name='login' value='Login' class='button' /><br />
login_data = urllib.urlencode({'admin_userid' : 'admin',
                               'admin_password' : 'test',
                               'login' : 'Login'
                               })
resp = opener.open('http://somesite.com/adminpanel/index.php', login_data)
#you are now logged in and can access "members only" content.
#when your all done be sure to close it

webbrowser.open('http://somesite.com/adminpanel/index.php')

resp.close()
+4
2

URL-, cookie? , cookie, .

webbrowser.open('http://somesite.com/adminpanel/index.php')

html resp html , html , .

for html in resp:
    print html
0
0

Source: https://habr.com/ru/post/1524140/


All Articles