How do you view the request headers that mechanize is using?

你离开我真会死。 提交于 2019-12-03 08:43:49

Are you asking how to see what headers your browser or mechanize is sending?


Browser

Like the other commentators say you can check the headers sent by the browsers with a plugin like Firebug (Firefox), Developer tools (IE 'F12', Chrome Developer tools and Opera Dragonfly) etc.


Mechanize

With mechanize you can get a copy of the headers sent by doing something like

import mechanize 

br = mechanize.Browser()
br.open("http://stackoverflow.com")
request = br.request
request.header_items()

Which gives in this case

[('Host', 'stackoverflow.com'), ('User-agent', 'Python-urllib/2.7')]

Other/One off

As always for a one off debug or if nothing is provided then you can use Wireshark to check what headers are been sent over the network. Tip: use a filter like (http.request.uri == "http://stackoverflow.com/")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!