How can I execute a HEAD request in a mechanization library?

I know how to make a HEAD request using httplib, but I have to use the mechanization for this site.

Essentially, I need to do to get the value from the header (file name) without actually downloading the file.

Any suggestions how could I do this?

+3
source share
2 answers

Mechanizing yourself only sends GET and POST, 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()
+8
source

In mechanization, you do not need to do the HeadRequest class, etc.

Simply


import mechanize

br = mechanize.Browser()

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

print r.info()

What all.

0
source

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


All Articles