【问题标题】:What's the easiest way to request a list of web pages from a web server one by one?从网络服务器逐一请求网页列表的最简单方法是什么?
【发布时间】:2013-08-28 15:01:34
【问题描述】:

给定一个 URL 列表,如何实现以下自动化任务(假设 windows 和 ubuntu 是可用的 O/Ses)?是否有现有类型的工具可以使实现这一点更容易或开箱即用?

log in with already-known credentials
for each specified url 
  request page from server
  wait for page to be returned (no specific max time limit)
  if request times out, try again (try x times)
  if server replies, or x attempts failed, request next url
end for each
// Note: this is intentionally *not* asynchronous to be nice to the web-server.

背景:我正在实现一个工作工具,该工具将从网络服务器请求页面,因此这些页面需要处理的数据将被缓存以备后用。工作人员不关心结果页面的内容,尽管它可能关心 HTML 状态代码。我考虑过幻像/casper/node 设置,但对这项技术不是很熟悉,也不想重新发明轮子(尽管它会很有趣)。

【问题讨论】:

标签: node.js automation web-crawler


【解决方案1】:

您可以使用 http 模块轻松请求页面。

Here's an example.

有些人更喜欢 npm 中提供的请求模块。

Here's a link to the github page

如果你需要更多,你可以使用 phantomjs。

Here's a link to the github page for bridging node and phantom

不过,您也可以寻找用于发出请求的简单 cli 命令,例如 wgetcurl

【讨论】:

  • 我决定采用节点路由,但我没有让节点进行爬行,而是生成了一个 Casper 进程。节点处理响应作业请求并提供状态更新。我认为从长远来看,单独使用 Phantom/Casper 会使其更加灵活。决定反对 Node 的幻像模块,因为人们似乎在 Casper 和 node 上取得了不同的成功,因为他们使用了不同的 javascript 引擎。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-26
  • 2018-04-16
  • 1970-01-01
相关资源
最近更新 更多