python login to website, no "id" only "class" for login button -
have been searching , searching, testing , trying, reading , reading... not programmer, , not pick these things quickly.
here code:
import requests url = 'http://company.page.com/member/index.php' (this url has form on it) values = {'username': 'myusernamehere', 'password': 'mypasswordhere'} r = requests.post(url, data=values) # have logged in url = "http://company.page.com/member/member.php" (this resulting url after logging in) # sending cookies result = requests.get(url, cookies=r.cookies) print (result.headers) print (result.text)
i error:
<form action="http://company.page.com/member/index.php" method="post" id="login"> <h3 class="head">donor login</h3> <em class="notice"><p class="errors">you must log in</p><br />
image of website source code: (first way figure out how post html)
use session
. or cookies not kept.
import requests s = requests.session() # <-- url = 'http://company.page.com/member/index.php' values = {'username': 'myusernamehere', 'password': 'mypasswordhere'} r = s.post(url, data=values) # session.post instead of requests.post # have logged in url = "http://company.page.com/member/member.php" (this resulting url after logging in) result = s.get(url) # use session.get , not specify cookies. print (result.headers) print (result.text)
Comments
Post a Comment