[Node.js] Web Scraping with Pagination and Advanced Selectors
When web scraping, you'll often want to get more than just one page of data. Xray supports pagination by finding the "next" or "more" button on each page and cycling through each new page until it can no longer find that link. This lesson demonstrates how to paginate as well as more advanced selectors for when links are difficult to scrape.
/**
* Created by Answer1215 on 8/22/2015.
*/
var Xray = require('x-ray');
var xray = new Xray(); xray('https://news.ycombinator.com/', '.athing', [{
rank: '.rank',
title: 'td:nth-child(3) a',
link: "td:nth-child(3) a@href"
}])
.paginate('a[rel="nofollow"]:last-child@href')
.limit(3)
.write('./results2.json'); ///////////////////////////////
// test
/////////////////////////////// xray('https://news.ycombinator.com/', 'a[rel="nofollow"]', [{
show: ''
}]).write('./results2.json');
/**
* [
{
"show": "Segment is hiring security engineers to help secure our container fleet"
},
{
"show": "Modafinil for cognitive neuroenhancement: a systematic review"
},
{
"show": "Ports and Power in the Indian Ocean"
},
{
"show": "Natural and Artificial Intelligence (1988) [pdf]"
},
{
"show": "Proofing Spirits with a Homemade Electrobalance"
},
{
"show": "Seth Nickell on Replacing the Aging Init Procedure on Linux (2003)"
},
{
"show": "More"
}
]
* */ xray('https://news.ycombinator.com/', 'a[rel="nofollow"]:last-child', [{
show: ''
}]).write('./results2.json');
/*
* [
{
"show": "More"
}
]
* */
[Node.js] Web Scraping with Pagination and Advanced Selectors的更多相关文章
- 利用OpenShift托管Node.js Web服务进行微信公众号开发
最近写了一个微信的翻译机器人.用户只要关注该公众号,发送英文的消息,就能收到中文翻译的回复.有兴趣的读者可以扫描下面的二维码关注该公众号,尝试发送英文单词试试看.(有时候第一次发送单词会收到“该公众号 ...
- Koa – 更加强大的下一代 Node.js Web 框架
Koa 是 Express 的开发团队设计的下一代 Web 框架,其目的是为 Web 应用程序提供更小,更具表现力,更坚实的基础.Koa 没有核捆绑任何中间件,并提供了一套优雅的方法,使服务器端开 ...
- node.js Web应用框架Express.js(一)
什么是Express.js Express 是一个简洁而灵活的 node.js Web应用框架, 提供一系列强大特性帮助你创建各种Web应用,提供丰富的HTTP工具以及来自Connect框架的中间件随 ...
- Node.js Web模块
什么是Web服务器? Web服务器是处理由HTTP客户端发送的,如web浏览器的HTTP请求的软件应用程序,并返回响应于客户端网页. Web服务器通常伴随着图片,样式表和脚本的HTML文档. 大多数W ...
- KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架
koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...
- 基于 Koa.js 平台的 Node.js web 快速开发框架KoaHub.js demo 可安装
KoaHub.js demo KoaHub.js KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Fu ...
- Node.js web快速入门 -- KoaHub.js
介绍 KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, Async & ...
- KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-yilianyun
koahub-yilianyun 微信易联云打印机接口 koahub-yilianyun易联云打印机node接口 Installation $ npm install koahub-yilianyun ...
- 《Node.js入门》CentOS 6.5下Node.js Web开发环境搭建笔记
近期想尝试一下英特尔的基于WebRTC协同通信开发套件,所以须要在本地搭建Node.js Web的开发測试环境. 这里讲的是CentOS 下的搭建方法.使用Windows的小伙伴请參考: <No ...
随机推荐
- MYSQL数据库备份与恢复【转】
mysqldump -h主机名 -P端口 -u用户名 -p密码 (–database) 数据库名 > 文件名.sql 在window上需要通过CMD进入mysql安装目录下的bin目录下执行 ...
- Firebird/InterBase内置函数使用说明
Firebird/InterBase内置函数使用说明(转自:圣域天堂) 2008-10-12 20:56 加*号为FB2.0加入的函数 整理:剑雷(jianlei) 2006-10-13 1. COU ...
- [BZOJ 1009] [HNOI2008] GT考试 【AC自动机 + 矩阵乘法优化DP】
题目链接:BZOJ - 1009 题目分析 题目要求求出不包含给定字符串的长度为 n 的字符串的数量. 既然这样,应该就是 KMP + DP ,用 f[i][j] 表示长度为 i ,匹配到模式串第 j ...
- OneAPM Cloud Test——系统性能监控神器
2015 年 8 月,OneAPM 推出了一款系统性能监控产品--Cloud Test,产品上线以来以「两低一高」的特点迅速成为市场增长率最快的一匹黑马.「两低一高」,即低使用成本.低学习成本以及高服 ...
- [topcoder]BestRoads
http://community.topcoder.com/stat?c=problem_statement&pm=10172&rd=13515 http://community.to ...
- Android Bitmap是不能比较的,这样做是错误的
代码1: Bitmap dir = BitmapFactory.decodeResource(context.getResources(), R.drawable.netdisc_search_lis ...
- android ListView异步加载图片(双缓存)
首先声明,参考博客地址:http://www.iteye.com/topic/685986 对于ListView,相信很多人都很熟悉,因为确实太常见了,所以,做的用户体验更好,就成了我们的追求... ...
- Android textAppearance的属性设置及TextView属性详解
textAppearance的属性设置 android:textAppearance="?android:attr/textAppearanceSmall" android:tex ...
- 【HDOJ】1695 GCD
莫比乌斯反演简单题目. /* 1695 */ #include <iostream> #include <string> #include <map> #inclu ...
- 一起啃PRML - 1.2.1 Probability densities 概率密度
一起啃PRML - 1.2.1 Probability densities @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ 我们之前一直在讨论“谁取到 ...