如何使用mechanize库执行HEAD请求? [英] How can I perform a HEAD request with the mechanize library?
本文介绍了如何使用mechanize库执行HEAD请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用httplib执行HEAD请求,但我必须为此站点使用mechanize。
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?
推荐答案
Mechanize本身只发送GET和POST,但你可以轻松扩展请求类发送HEAD。示例:
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()
这篇关于如何使用mechanize库执行HEAD请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文