Python Requests GET and POST to website with verification token -


i'm using python 3.3 , requests library basic post request.

i want simulate happens if manually enter information browser webpage: https://capp.arlingtonva.us/tap/ac_xwtappay.aspx. example, try entering "2. parking tickets", clicking next, entering 1234 plate number , virginia state , clicking next, , checking checkbox , clicking next.

although url same, there multiple iterations of inputting information , clicking next.

currently, doing on url randomly generated strings values "__eventvalidation" , "__viewstate" in source code. post information other information.

am using right post payload below in code?

my code is:

import requests url = r'https://capp.arlingtonva.us/tap/ac_xwtappay.aspx'  #get request s = requests.session() r = s.get(url) text1 = r.text  #getting "__eventvalidation" value: eventvalstartstring = r'id="__eventvalidation" value="' eventvalstart = text1.find(eventvalstartstring)+len(eventvalstartstring) end_ind = text1.find('"',eventvalstart) eventvalidation_string = text1[eventvalstart:end_ind]  #getting "__viewstate" value: viewstate_start_string= 'id="__viewstate" value="' viewstate_start = text1.find(viewstate_start_string)+len(viewstate_start_string) end_ind2 = text1.find('"',viewstate_start) viewstate_string = text1[viewstate_start:end_ind2]  #post request payload = {"ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:billtype":"pkt",            "__eventtarget":"",            "__eventargument":"",            "__lastfocus":"",            "__viewstate":viewstate_string,            "__viewstategenerator":"c0c9f6bc",            "__viewstateencrypted":"",            "__eventvalidation":eventvalidation_string,            "ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:tagstate":'va',            "ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:tagnumber":'1234',            "ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:next1":"next >",            "ac_xwtapctl:scrolltop":'0',            "ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:next2":"next >",            "ac_xwtapctl:xwtap_txtfocus":"ac_xwtapctl_ac_xwtapctlctl.xuwrqctl_next1",            "ac_xwtapctl_scrolltop":'0',            "ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:next3":"next >",            "ac_xwtapctl:xwtap_txtfocus":"ac_xwtapctl_ac_xwtapctlctl.xuwrqctl_next2",            "ac_xwtapctl_scrolltop":"0"}  post = s.post(url, data=payload) text = post.text 

thanks, -k.

at stage i'd switch using beautifulsoup (pip install beautifulsoup4) parse html make easier data out. because it's .net (i think) there's 1 form whole page grab out inputs.

import requests bs4 import beautifulsoup  s = requests.session()  r = s.get('https://capp.arlingtonva.us/tap/ac_xwtappay.aspx') soup = beautifulsoup(r.text)  # grab out fields payload = {i['name']:i.get('value') in soup.findall('input')} # populate select field payload['ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:billtype'] = 'pkt'  # , submit next step r = s.post('https://capp.arlingtonva.us/tap/ac_xwtappay.aspx', data=payload)      # parse / build next request etc soup = beautifulsoup(r.text) payload = {i['name']:i.get('value') in soup.findall('input')} payload['ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:tagstate'] = 'va' payload['ac_xwtapctl:ac_xwtapctlctl.xuwrqctl:tagnumber'] = 'blah' r = s.post('https://capp.arlingtonva.us/tap/ac_xwtappay.aspx', data=payload)      # rinse , repeat many times required... soup = beautifulsoup(r.text) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -