基于Node.js的爬虫工具 – Node Crawler
Node Crawler的目标是成为最好的node.js爬虫工具,目前已经停止维护。
我们来抓取光合新知博客tech栏目中的文章信息。
访问http://dev.guanghe.tv/category/tech/
,右键查看页面源代码,可以看到文章信息等内容,如下所示:
1
2
3
4
5
6
7
8
9
10
11
|
<ul class="posts">
<li>
<span class="post-date">Dec 31, 2015</span>
<a class="post-link" href="/2015/12/Getting-Started-With-React-And-JSX.html">React和JSX入门指导</a>
</li>
<li>
<span class="post-date">Dec 30, 2015</span>
<a class="post-link" href="/2015/12/ReactJS-For-Stupid-People.html">React 懒人教程</a>
</li>
</ul>
|
因为每篇文章都是一个<li>
标签,所以我们从页面代码的所有<li>
中获取文章的发布时间、链接和标题。
爬虫代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
var Crawler = require('crawler');
var crawler = new Crawler({
maxConnections: 10,
callback: function(err, result, $) {
$('li').each(function(index, li) {
console.log(index + ' :');
console.log('time:' + $(li).children(0).text());
console.log('url:' + result.uri + $(li).children(1).attr('href'));
console.log('title:' + $(li).children(1).text());
});
}
});
crawler.queue('http://dev.guanghe.tv/category/tech/');
|
npm install
安装crawler模块,node app.js
运行程序。
你将会获得如下内容(仅展示部分内容):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
0 :
time:Dec 31, 2015
url:http://dev.guanghe.tv/category/tech//2015/12/Getting-Started-With-React-And-JSX.html
title:React和JSX入门指导
1 :
time:Dec 30, 2015
url:http://dev.guanghe.tv/category/tech//2015/12/ReactJS-For-Stupid-People.html
title:React 懒人教程
2 :
time:Dec 24, 2015
url:http://dev.guanghe.tv/category/tech//2015/12/iOSCustomProblem.html
title:iOS开发常见问题
3 :
time:Dec 17, 2015
url:http://dev.guanghe.tv/category/tech//2015/12/iOSXcodeDebug.html
title:Xcode Debug技巧
|
基于Node.js的爬虫工具 – Node Crawler的更多相关文章
- 一个最简单 node.js 命令行工具
一个最简单 node.js 命令行工具 node.js cli $ node cli.js xyz # OR $ node cli xyz 接受参数 process.argv js "use ...
- 基于node.js制作爬虫教程
前言:最近想学习node.js,突然在网上看到基于node的爬虫制作教程,所以简单学习了一下,把这篇文章分享给同样初学node.js的朋友. 目标:爬取 http://tweixin.yueyishu ...
- Node.js 网页爬虫再进阶,cheerio助力
任务还是读取博文标题. 读取app2.js // 内置http模块,提供了http服务器和客户端功能 var http=require("http"); // cheerio模块, ...
- Node.js:常用工具util
概要:本篇博客的主要内容是介绍node.js的常用工具util. 1.util.inherits util.inherits(constructor,superConstructor)是一个实现对象间 ...
- Node.js 命令行工具的编写
日常开发中,编写 Node.js 命令行工具来完成一些小任务是很常见的操作.其编写也不难,和日常编写 Node.js 代码并无二致. package.json 中的 bin 字段 一个 npm 模块, ...
- 实用的 Node.js 教程,工具和资源
这里分享一批实用的实用的 Node.js 教程,工具和资源. Node.js是一个建立在Chrome之上的JavaScript运行时平台,可方便地构建快速,可扩展的网络应用程序.Node.js使用事件 ...
- 【Node.js】2.开发Node.js选择哪个IDE 开发工具呢
安装完Node.js之后,就要为它选择一个有利的IDE用于开发. 相比较了多个IDE之后,定位在webstrom和sublime上. 有一个简单的比较: webstorm功能很丰富,前端开发工具的集大 ...
- node.js入门系列(一)--Node.js简介
什么是NodeJS JS是脚本语言,脚本语言都需要一个解析器才能运行.对于写在HTML页面里的JS,浏览器充当了解析器的角色.而对于需要独立运行的JS,NodeJS就是一个解析器. 每一种解析器都是一 ...
- Node.js的安装以及Node.js的模块管理
索引: Node.js的安装以及Node.js的模块管理Node.js开发环境搭建以及对ES6的支持Node.js构建Vue.js项目Vue.js单文件组件的开发基于Vue.js的UI组件(Eleme ...
随机推荐
- poj_2823 线段树
题目大意 给定一行数,共N个.有一个长度为K的窗口从左向右滑动,窗口中始终有K个数字,窗口每次滑动一个数字.求各个时刻窗口中的最大值和最小值. 题目分析 直接搜索,复杂度为O(n^2).本题可以看做是 ...
- SaltStack之编译安装LNMP环境
使用saltstack编译安装LNMP环境 一,系统版本查看 二,安装salt-master和salt-minion 安装配置过程参考SaltStack概述及安装 三,修改配置文件 /etc/salt ...
- CodeForces 731A Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Every write operation executed on a document, deletes included
Delete API | Elasticsearch Reference [6.5] | Elastic https://www.elastic.co/guide/en/elasticsearch/r ...
- EIT: where is it now and what lies ahead?
EIT: where is it now and what lies ahead? Electrical impedance tomography (EIT) is an emerging clini ...
- JUnit4.12 源码分析(二)之TestRule
1. TestRule TestRule和@Before,@After,@BeforeClass,@AfterClass功能类似,但是更加强大; JUnit 识别TestRule的两种方式: 方法级别 ...
- 年假小 Plan
Learn 董伟明 课程 https://www.pycourses.com/ Learn 500 Lines or Less https://github.com/HT524/500LineorLe ...
- WebHDFS vs HttpFS GateWay
基于hadoop 2.7.1版本 一.简介 1. WebHDFS官方简介: Introduction The HTTP REST API supports the complete FileSyste ...
- Ubuntu apt-get更换阿里云源
sudo vim /etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe ...
- Uboot命令U_BOOT_CMD
转载:http://blog.csdn.net/shengzhadon/article/details/52766263 U_BOOT_CMD是一个宏定义,具体功能是定义一个struct cmd_tb ...