E
E
Evgeny Elizarov2012-10-08 15:37:56
Python
Evgeny Elizarov, 2012-10-08 15:37:56

Python, urllib, how to get data from debug?

I'm trying to login to the site to get cookies, the code is like this:

def login(login, password) :
  data = urllib.urlencode({'shop_user[login]': login, 'shop_user[pass]': password, 'shop_user[mem]': 'on', 'auth': '%E2%EE%E9%F2%E8+%ED%E0+%F1%E0%E9%F2'})
  headers = {"User-Agent" : "Mozilla/5.0", "Accept" : "application/x-www-form-urlencoded"}
  request = urllib2.Request(url, data, headers)
  httpHandler = urllib2.HTTPHandler()
  httpHandler.set_http_debuglevel(1)
  opener = urllib2.build_opener(httpHandler)
  urlHandle = opener.open(request)

Login happens, in debug mode it shows cookies that I actually need, the question is how can I pull them out now? I understand that the debug exhaust itself is not “tied” to anything. Is it possible to equate it somewhere to a variable in order to parse it? Or what are the options? Tell me please.
ps it has nothing to do with the theft of content, if that.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
alternativshik, 2012-10-08
@alternativshik

request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
print response.headers['Set-Cookie']
wrote from memory. Check. :)

A
alternativshik, 2012-10-08
@alternativshik

so in the set-cookie header all cookies are in the form cookie1=value1&cookie2=value2

V
Voldemar Duletsky, 2012-10-08
@r00t_aka_spin

I recommend using PyCharm - there is a tracer of all variables

A
alternativshik, 2012-10-08
@alternativshik

Then via cookielib www.codercaste.com/2009/11/28/how-to-use-the-urllib-python-library-to-fetch-url-data-and-more/

E
EXSlim, 2012-10-08
@EXSlim

if possible, better use requests and its Session

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question