本文介绍了使用python从网页抓取标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用python 3访问HTTP标头。具体来说,我正在尝试重新创建您可以通过网络在Chrome中的开发人员工具中访问的标题。
How can I use python 3 to get access to the HTTP Headers. Specifically, I am trying to recreate the headers you can gain access to through network in the developer tools in chrome.
推荐答案
>>> import pprint
>>> import urllib.request
>>> u = urllib.request.urlopen('http://www.python.org')
>>> pprint.pprint(dict(u.getheaders()))
{'Accept-Ranges': 'bytes',
'Connection': 'close',
'Content-Length': '18882',
'Content-Type': 'text/html',
'Date': 'Sat, 24 Dec 2011 23:51:27 GMT',
'ETag': '"105800d-49c2-4b4ab1ba443c0"',
'Last-Modified': 'Thu, 22 Dec 2011 09:41:43 GMT',
'Server': 'Apache/2.2.16 (Debian)',
'X-Pad': 'avoid browser bug'}
这篇关于使用python从网页抓取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!