python - Python3 - how to login to web form with hidden values? -
i trying write python script login following site in order automatically keep on eye on of our merchant account details:
https://secure.worldpay.com/sso/public/auth/login.html?serviceidentifier=merchantadmin
the credentials using read-only, cannot used nefarious, isn't quite working correctly.
my code far:
import urllib requests import session login_url = "https://secure.worldpay.com/sso/public/auth/login.html?serviceidentifier=merchantadmin" _page = urllib.urlopen(login_url) _contents = _page.read() _jlbz_index = _contents.find("jlbz") _jlbz_start_index = _jlbz_index + 5 _jlbz_end_index = _jlbz_start_index + 41 jlbz = _contents[_jlbz_start_index:_jlbz_end_index] fdt = _contents.find("formdisplaytime") fdt_start_index = fdt + 23 fdt_end_index = fdt_start_index + 13 form_display_time = _contents[fdt_start_index:fdt_end_index] fsh = _contents.find("formsubmithash") fsh_start_index = fsh + 22 fsh_end_index = fsh_start_index + 41 form_submit_hash = _contents[fsh_start_index:fsh_end_index] post_auth_url = "https://secure-test.worldpay.com/merchant/common/start.html?jlbz={0}".format(jlbz) payload = { "action": "j_security_check", "username": "username", "password": "password", "jlbz": jlbz, "maiversion": "version1", "formdisplaytime": form_display_time, "formsubmithash": form_submit_hash } session() c: c.post(login_url, data=payload) request = c.get(post_auth_url) print(request.headers) print(request.text)
i know little long-winded find easier write little verbosely when first trying something, , refining later.
jlbz, formdisplaytime , formsubmithash hidden input values page source - scraping page, when c.post, i'm opening url again, these values changing , no longer valid? however, i'm unsure how rewrite c.post line ensure extract correct hidden values submission?
i don't think relevant site, site hidden random values?
import requests bs4 import beautifulsoup user='xyzmohsin' passwd='abcpasswd' s=requests.session() headers={"user-agent":"mozilla/5.0 (x11; linux i686) applewebkit/537.36 (khtml, gecko) chrome/36.0.1985.125 safari/537.36"} s.headers.update(headers) r=s.get("https://secure.worldpay.com/sso/public/auth/login.html?serviceidentifier=merchantadmin") soup=beautifulsoup(r.content) jlbz=soup.find("input",{"name":"jlbz"})['value'] maiversion=soup.find(id="maiversion")['value'] formdisplaytime=soup.find("input",{"name":"formdisplaytime"})['value'] formsubmithash=soup.find("input",{"name":"formsubmithash"})['value'] data={"jlbz":jlbz, "username":user, "password":passwd, "maiversion":maiversion, "formdisplaytime":formdisplaytime, "formsubmithash":formsubmithash} headers={"content-type":"application/x-www-form-urlencoded", "host":"secure.worldpay.com", "origin":"https://secure.worldpay.com", "referer":"https://secure.worldpay.com/sso/public/auth/login.html?serviceidentifier=merchantadmin"} login_url="https://secure.worldpay.com/sso/public/auth/j_security_check" r=s.post(login_url,headers=headers,data=data)
i don't have id , password, hence don't know headers work. if doesn't work please remove host, origin , referer
last s.post
request's header
hope helps :-)
Comments
Post a Comment