0

Is there any way of grabbing the html source code from here? I'm sending a post login request to a website, and if the response status is 302 I want to check the source code. I couldn't find away to do this. Here is what I have:

    http = httplib2.Http()
    url = "http://example.com"
    login = "test"
    password = "test"
    body = {'login': login, 'password' : password}
    headers = {'Content-type' : 'application/x-www-form-urlencoded'}
    response, content = http.request(url, 'POST', headers=headers, body=urllib.urlencode(body))

    if response.status == '302':
        break

"break" is where I need to get the html source code.

RydallCooper
  • 19,094
  • 1
  • 11
  • 17
  • Are you sure there is a body to "grab"? I don't recall ever seeing a 302 with a body (unless it was trying to target browsers that don't honor a 302 and includes some html with a meta refresh tag.) – sberry Mar 23 '14 at 03:33
  • Not necessarily grabbing the body with httplib, but grab the body without having to login using something else? – RydallCooper Mar 23 '14 at 03:35
  • Where does the location header in the 302 response take you? Is that what happens during a successful login? – sberry Mar 23 '14 at 03:49
  • Yes, when it gets 302 it logins successfully. When it gets 200 it fails. – RydallCooper Mar 23 '14 at 04:26
  • So, read the location header, and open the request to wherever it points you. The one thing is you will have to keep track of your cookies. – sberry Mar 23 '14 at 04:34

0 Answers0