python - Enabling cookies with urllib -
i parse website urllib python library. wrote
import urllib web source_rep.urlopen(url_rep).read() print source_rep
the website returns me message saying should enable cookie. how can python?
by using cookiejar
, of course!
and urllib2
.
import cookielib import urllib2 cookiejar= cookielib.lwpcookiejar() opener= urllib2.build_opener( urllib2.httpcookieprocessor(cookiejar) ) opener.urlopen(...)
as aside:
in experience, site want parse telling enable cookies indicator going unpleasant experience, , you'll asking how enable javascript in urllib2
next (which not answerable, way).
if think you'll benefit higher-level approach, should evaluate mechanize
, selenium.
Comments
Post a Comment