比较来自世界各地的卖家的域名和 IT 服务价格

如何最有效地拆卸网页 Node.js

我需要拆卸一个简单的网页并获取数据 html, 如那个 "src", "data-attr" 等等。如何最有效地使用它 Node.js? 如果它有帮助,我使用 Node.js 0.8.x.

P.S. 这是
http://tunes.io/
, 我明白了。 我想获取当前曲目列表并制作自己的应用程序 html5 用于在移动设备上侦听。
已邀请:

董宝中

赞同来自:

我多次做了。 你想用
http://phantomjs.org/
, 如果您清洁的网站,非常使用 JavaScript. 注意 PhantomJS - 不是 Node.js. 这是一个完全不同的履行环境。 JavaScript. 你可以整合
https://github.com/sgentle/phantomjs-node
或者
https://github.com/alexscheelmeyer/node-phantom
但他们都很漂亮卡其色。 YMMV 跟他们。 避免与之相关的一切 jsdom. 这将导致头疼,它包括
http://zombie.labnotes.org/
.

你应该使用什么 - 这是
https://github.com/MatthewMueller/cheerio
结合
https://github.com/mikeal/request
. 这对于大多数网页来说都足够了。

我写了一篇关于使用的博客帖子 Cheerio 要求:
http://procbits.com/2012/04/11 ... erio/
但是,再次,如果它 JavaScript 强烈,使用 PhantomJS 结合
http://casperjs.org/
.

我希望它会有所帮助。

使用请求和问候的斯莱普特:


var request = require/'request'/
, cheerio = require/'cheerio'/;

var searchTerm = 'screen+scraping';
var url = 'http://www.bing.com/search?q=' + searchTerm;

request/url, function/err, resp, body/{
$ = cheerio.load/body/;
links = $/'.sb_tlst h3 a'/; //use your CSS selector here
$/links/.each/function/i, link/{
console.log/$/link/.text// + ':\n ' + $/link/.attr/'href'//;
}/;
}/;

知食

赞同来自:

你可能会尝试
http://phantomjs.org/
. 这里
http://code.google.com/p/phant ... ation
通过使用它来清洁屏幕。

郭文康

赞同来自:

我同意 @JP 理查森,那 Cheerio 最适合清洁 non-JS-heavy 网站。
对于JS沉重的网站,使用
http://casperjs.org/
. 它提供了大量的抽象和风格的承诺 API. 他们转到如何在他们的文件中刮擦:
http://docs.casperjs.org/en/latest/quickstart.html
.

奔跑吧少年

赞同来自:

如果你想超越幻影,使用 node-phantom. 我有一个存储库 git hub, 一起使用它们来创建 pdf 文件来自 html, 如果你想看到。
但我不会去幻影,因为他比你通常想要的更多,而且 cheerio 快点。

要回复问题请先登录注册