1

Is there any Python HTTP library that helps to imitate one of popular web-browser and has HTTPS support? I would like to define the order of HTTP headers, the presence of each exact header, the order of cookies values - everything that relates to "fingerprint" of a browser. We need that to test specific web server.

4

2 回答 2

2

httplib.request将需要一个OrderedDictfor 标题。某些标头将自动添加以符合协议,如果您在提供的标头中指定它们,这些标头将被忽略。

查看putheaderand_send_request方法,如果它们的行为不符合您的目的,您可以覆盖它们。

>>> import httplib
>>> from collections import OrderedDict
>>> h = OrderedDict(('X-A','a'),('X-B','b'),('X-C','c'))
>>> c = httplib.HTTPConnection('localhost')
>>> c.set_debuglevel(1)
>>> r = c.request('GET','/','',h)
send: 'GET / HTTP/1.1\r\nHost: localhost\r\nAccept-Encoding: identity\r\nX-A: a\r\nX-B: b\r\nX-C: c\r\n\r\n'
于 2012-09-17T11:38:58.853 回答
0

查看Requests,它非常易于使用并且拥有您所需要的一切。或者,您可以使用Selenium从 Python驱动Web 浏览器本身

于 2012-09-17T12:43:56.257 回答