Wednesday 15 April 2015

python - Retrieve data from url while being logged in -


I need to retrieve the data from the URL for which the user has the url (https) issue that the user is only logged in. It can only get data during these (which is installed on the cookie set on his machine, as long as he is logged in) I am trying to build on these scenarios, but I am not able to retrieve the data while logging in. I am following these steps:
  import urllib2 Import urllib url1 = 'https: // url / user / login /' url2 = 'https: // Url / data / globe /' login_data = urllib.urlencode ({'username': 'username', 'password': ' Password ',' submit ':' log in '}) req1 = urllib2.Request (url1) response = Urllib2.urlopen (req1) cookie = response. Titles.get ('set-cookie') req2 = urllib2.Request (url2) req2.add_header ('cookie', cookie) response = urllib2.urlopen (req2) data = read response ()   

The data response is giving the printing indicator that basically reflects that the session cookie is not set .. so personal data is not coming back ... How to login using the first Url and then set the cookie And then retrieve data while logged in?

I should be stupid .. I was not even using the login data that I had created. Therefore, it is supposed to be:

  response = urllib2.urlopen (req1, login_data)   

and everything gets better for you all Thank you. : -)

No comments:

Post a Comment