title: Grab data using python
body: <p>Here website will list some data based on dropdown-filter, so i am trying to fetch those data by passing static dropdown values, but i think due to view state i am unable to grab those data.</p>
  
  <blockquote>
    <p>Anyone have any idea how to grab asp.net website data which is using viewstate?</p>
  </blockquote>
  
  <p>i am getting below error</p>
  
  <blockquote>
    <p>Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that &lt;machineKey&gt; configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.</p>
  </blockquote>
  
  <p><strong>Python Script</strong></p>
  
  <pre><code>import requests
  from bs4 import BeautifulSoup
  
  def get_viewstate():
  url = "http://xlnindia.gov.in/frm_G_Cold_S_Query.aspx?ST=GJ"
  req = requests.get(url)
  data = req.text
  
  bs = BeautifulSoup(data)
  return bs.find("input", {"id": "__VIEWSTATE"}).attrs['value']
  
  url = "http://xlnindia.gov.in/frm_G_Cold_S_Query.aspx?ST=GJ"
  data = {"__VIEWSTATE": get_viewstate(),"ST":'GJ', "ddldistrict":'AMR', "ddltaluka":'' ,"btnSearch":'Search'}
  req = requests.post(url, data)
  
  bs = BeautifulSoup(req.text)
  print(bs.prettify())
  </code></pre>