【问题标题】:Grabbing headers from webpage with python使用python从网页中抓取标题
【发布时间】:2011-12-24 23:43:09
【问题描述】:

如何使用 python 3 访问 HTTP 标头。具体来说,我正在尝试在 chrome 的开发人员工具中重新创建可以通过网络访问的标头。

【问题讨论】:

  • @Vladiki 请您将其中一个答案标记为已接受。

标签: python html http python-3.x


【解决方案1】:
>>> 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'}

【讨论】:

  • 谢谢,我想我知道我需要什么了。找到了一种解决方法,这样我就不需要标题了
猜你喜欢
  • 2019-01-05
  • 1970-01-01
  • 2016-03-14
  • 1970-01-01
  • 2016-02-05
  • 2014-10-30
  • 1970-01-01
  • 2016-10-19
相关资源
最近更新 更多