How to get an http page using mechanized cookies?

There is a Python mechanization object with a form with almost all set values, but not yet presented. Now I want to extract another page using cookies from a Mechanicalize instance, but without resetting the page, forms, etc., for example. so that the values ​​remain set (I just need to get the body line of another page, nothing more). So there is a way:

  • Tell me to mechanize not reset the page (maybe through UserAgentBase)?
  • Make urllib2use the forge mechanize cookie? NB: urllib2.HTTPCookieProcessor(self.br._ua_handlers["_cookies"].cookiejar)not working.
  • Any other way to pass cookies to urllib?
+3
source share
3

:

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.br._ua_handlers["_cookies"].cookiejar))
opener.open(imgurl)
+5

, , Mechanicalize,

from copy import deepcopy
br = Browser()
br.open("http://www.example.com/")
# Make a copy for doing other stuff with
br2 = deepcopy(br)
# Do stuff with br2
# Now do stuff with br
+2

:

  • Get a second page before filling out the form?
  • Or get a new page and then goBack ()? Although, perhaps this will reset the values.
+2
source

Source: https://habr.com/ru/post/1719166/


All Articles