3

I know how to do a HEAD request with httplib, but I have to use mechanize for this site.

Essentially, what I need to do is grab a value from the header (filename) without actually downloading the file.

Any suggestions how I could accomplish this?

bignose
  • 30,281
  • 14
  • 77
  • 110
Jeremy Cantrell
  • 26,392
  • 13
  • 55
  • 78

2 Answers2

8

Mechanize itself only sends GETs and POSTs, but you can easily extend the Request class to send HEAD. Example:

import mechanize

class HeadRequest(mechanize.Request):
    def get_method(self):
        return "HEAD"

request = HeadRequest("http://www.example.com/")
response = mechanize.urlopen(request)

print response.info()
Michał Kwiatkowski
  • 9,196
  • 2
  • 25
  • 20
0

In mechanize there is no need to do HeadRequest class etc.

Simply


import mechanize

br = mechanize.Browser()

r = br.open("http://www.example.com/")

print r.info()

That's all.

Nuncjo
  • 1,290
  • 3
  • 15
  • 16