py3.x urllib.request - HTTPCookieProcessor and header adding

G

gervaz

Hi all, I need to fetch some html pages and it is required to have
cookies enabled. So, I'm using

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor
())
urllib.request.install_opener(opener)

as a global instance. Is there a way to always use a default header
like:

{"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.1.5) Gecko/20091102 Firefox/3.5.5"}

instead of always creating urllib.request.Request(my_url, None,
headers) and call different urls with the same
cookies?

Thanks, Mattia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top