【发布时间】:2011-11-28 04:12:09
【问题描述】:
我正在编写一个爬虫,它会定期检查新闻网站列表中的新文章。 我已经阅读了有关避免不必要页面下载的不同方法,基本上确定了 5 个标题元素,这些元素可能有助于确定页面是否已更改:
- HTTP 状态
- ETAG
- Last_modified(与 If-Modified-Since 请求结合使用)
- 过期
- 内容长度。
优秀的FeedParser.org 似乎实现了其中一些方法。
我正在寻找做出这种决定的 Python(或任何类似语言)的最佳代码。 请记住,标头信息始终由服务器提供。
可能是这样的:
def shouldDonwload(url,prev_etag,prev_lastmod,prev_expires, prev_content_length):
#retrieve the headers, do the magic here and return the decision
return decision
【问题讨论】:
标签: python http-headers etag web-crawler if-modified-since