title: How to call a postback in ASP.Net with Python
body: <p>I am trying to web-scrape some elements and their values off a page with <strong>Python</strong>; However, to get more elements, I need to simulate a click on the <em>next button</em>. There is a post back tied to these buttons, so I am trying to call it. Unfortunately, Python is only printing the same values over and over again [meaning the post back for the <em>next button</em> isn't being called]. I am using <code>requests</code> to do my POST/GET.</p>
  
  <pre><code>import re
  import time
  import requests
  
  TARGET_GROUP_ID = 778092
  
  
  SESSION = requests.Session()
  REQUEST_HEADERS = {"Accept-Encoding": "gzip,deflate"}
  GROUP_URL = "http://roblox.com/groups/group.aspx?gid=%d"%(TARGET_GROUP_ID)
  POST_BUTTON_HTML = 'pagerbtns next'
  
  EVENTVALIDATION_REGEX = re.compile(r'id="__EVENTVALIDATION" value="(.+)"').search
  VIEWSTATE_REGEX = re.compile(r'id="__VIEWSTATE" value="(.+)"').search
  VIEWSTATEGENERATOR_REGEX = re.compile(r'id="__VIEWSTATEGENERATOR" value="(.+)"').search
  TITLE_REGEX = re.compile(r'&lt;a id="ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_ctrl\d+_hlAvatar".*?title="(\w+)".*?ID=(\d+)"')
  page = SESSION.get(GROUP_URL, headers = REQUEST_HEADERS).text
  while 1:
      if POST_BUTTON_HTML in page:
          for (ids,names) in re.findall(TITLE_REGEX, page):
              print ids,names
          postData = {
              "__EVENTVALIDATION": EVENTVALIDATION_REGEX(page).group(1),
              "__VIEWSTATE": VIEWSTATE_REGEX(page).group(1),
              "__VIEWSTATEGENERATOR": VIEWSTATEGENERATOR_REGEX(page).group(1),
              "__ASYNCPOST": True,
              "ct1000_cphRoblox_rbxGroupRoleSetMembersPane_currentRoleSetID": "4725789",
              "ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl02$ctl00": "",
              "ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl01$HiddenInputButton": "",
              "ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl01$PageTextBox": "3"
          }
          page=SESSION.post(GROUP_URL, data = postData, stream = True).text
      time.sleep(2)
  </code></pre>
  
  <p>How can I properly call the post back in ASP.NET from Python to fix this issue? As stated before, it's only printing out the same values each time.</p>
  
  <p>This is the HTML Element of the button</p>
  
  <pre><code>&lt;a class="pagerbtns next" href="javascript:__doPostBack('ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl02$ctl00','')"&gt;&amp;nbsp;&lt;/a&gt;
  </code></pre>
  
  <p>And this is the div it is in:</p>
  
  <pre><code>&lt;div id="ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_Footer_ctl01_MembersPagerPanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_Footer_ctl01_HiddenInputButton')"&gt;
   &lt;div id="ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_Footer_ctl01_Div1" class="paging_wrapper"&gt;
  Page &lt;input name="ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl01$PageTextBox" type="text" value="1" id="ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_Footer_ctl01_PageTextBox" class="paging_input"&gt; of 
  &lt;div class="paging_pagenums_container"&gt;125&lt;/div&gt;
  &lt;input type="submit" name="ctl00$cphRoblox$rbxGroupRoleSetMembersPane$dlUsers_Footer$ctl01$HiddenInputButton" value="" onclick="loading('members');" id="ctl00_cphRoblox_rbxGroupRoleSetMembersPane_dlUsers_Footer_ctl01_HiddenInputButton" class="pagerbtns translate" style="display:none;"&gt;
  &lt;/div&gt;                      
  &lt;/div&gt;
  </code></pre>
  
  <p>I was thinking of using a JS library and executing the JS <code>__postback</code> method, however, I would like to first see if this can be achieved in pure Python.</p>