title: Executing JavaScript when opening a page
body: <p>I am currently new with HTTP parsing, I am using python to send and Receive requests in HTTP. I just have a small problem as the website I am dealing with in sending requests does not just need Headers and POST. As when I click a button on the webpage there is a JavaScript code executed that tells the server to respond for my upcoming Request. </p>
  
  <p>So if I normally open the page with same headers and POST request it will just open it as a normal GET and will not read any of the data I supplied in the POST.</p>
  
  <p>My code : </p>
  
  <pre><code>import cookielib
  import urllib
  import urllib2
  
  
  
  
  # Store the cookies and create an opener that will hold them
  cj = cookielib.CookieJar()
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  
  # Add our headers
  opener.addheaders = [('User-agent', 'RedditTesting'),
                       ('Cookie', '')
                       ]
  
  
  urllib2.install_opener(opener)
  
  # The action/ target from the form
  authentication_url = 'http://plapal.pla/Search.aspx'
  
  # Input parameters we are going to send
  payload = {
    '_EVENTTARGET': 'btnSearch',
    '_VIEWSTATE': 'plapla',
    'ctl04%24ddNavigate': 'plapla',
    'chkDate': 'on',
    '_EVENTARGUMENT': '',
    '_LASTFOCUS': '',
    'txtResvCode': '',
    'txtCustName': '',
    'txtFromDate': '27%2F01%2F2013',
    'txtToDate': '27%2F09%2F2013',
    'ddSearchType': '1',
    'ddChannel': '-1',
    'ddNetGross': 'NET'
    }
  
  # Use urllib to encode the payload
  data = urllib.urlencode(payload)
  
  # Build our Request object (supplying 'data' makes it a POST)
  req = urllib2.Request(authentication_url, data)
  
  # Make the request and read the response
  resp = urllib2.urlopen(req)
  contents = resp.read()
  
  print contents
  </code></pre>
  
  <p>but it doesn't work. and in the webpage when I hover the Search button I get : </p>
  
  <pre><code>javascript:WebForm_DoPostBackWithOptions(new%20WebForm_PostBackOptions("btnSearch",%20"",%20true,%20"",%20"",%20false,%20true))
  </code></pre>
  
  <p>So how to execute this JS so I can actually Enter my Post Data.</p>