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的更多相关文章

  1. 利用OpenShift托管Node.js Web服务进行微信公众号开发

    最近写了一个微信的翻译机器人.用户只要关注该公众号,发送英文的消息,就能收到中文翻译的回复.有兴趣的读者可以扫描下面的二维码关注该公众号,尝试发送英文单词试试看.(有时候第一次发送单词会收到“该公众号 ...

  2. Koa – 更加强大的下一代 Node.js Web 框架

    Koa 是 Express 的开发团队设计的下一代 Web 框架,其目的是为 Web 应用程序提供更小,更具表现力,更坚实的基础.Koa 没有核捆绑任何中间件,并提供了一​​套优雅的方法,使服务器端开 ...

  3. node.js Web应用框架Express.js(一)

    什么是Express.js Express 是一个简洁而灵活的 node.js Web应用框架, 提供一系列强大特性帮助你创建各种Web应用,提供丰富的HTTP工具以及来自Connect框架的中间件随 ...

  4. Node.js Web模块

    什么是Web服务器? Web服务器是处理由HTTP客户端发送的,如web浏览器的HTTP请求的软件应用程序,并返回响应于客户端网页. Web服务器通常伴随着图片,样式表和脚本的HTML文档. 大多数W ...

  5. KoaHub.js是基于 Koa.js 平台的 Node.js web 快速开发框架

    koahubjs KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, A ...

  6. 基于 Koa.js 平台的 Node.js web 快速开发框架KoaHub.js demo 可安装

    KoaHub.js demo KoaHub.js KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Fu ...

  7. Node.js web快速入门 -- KoaHub.js

    介绍 KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架.可以直接在项目里使用 ES6/7(Generator Function, Class, Async & ...

  8. KoaHub.js -- 基于 Koa.js 平台的 Node.js web 快速开发框架之koahub-yilianyun

    koahub-yilianyun 微信易联云打印机接口 koahub-yilianyun易联云打印机node接口 Installation $ npm install koahub-yilianyun ...

  9. 《Node.js入门》CentOS 6.5下Node.js Web开发环境搭建笔记

    近期想尝试一下英特尔的基于WebRTC协同通信开发套件,所以须要在本地搭建Node.js Web的开发測试环境. 这里讲的是CentOS 下的搭建方法.使用Windows的小伙伴请參考: <No ...

随机推荐

  1. Linq语句与aspnetpager结合分页

    public void DataBindList()        {            List<EnDeContent> listCon = null;            in ...

  2. App 性能分析

    关键因素: ---- Instrument 性能分析神器 1. 启动时间 应用启动时间长短对用户第一次体验至关重要,同时系统对应用的启动.恢复等状态的运行时间也有严格的要求,在应用超时的情况下系统会直 ...

  3. 理解Python的迭代器

    首先,廖雪峰老师的教程中解释了迭代器和生成器,这篇文章只是补充和我个人的总结. 什么是迭代 可以直接作用于for循环的对象统称为可迭代对象(Iterable). 可以被next()函数调用并不断返回下 ...

  4. Kaggle Competition Past Solutions

    Kaggle Competition Past Solutions We learn more from code, and from great code. Not necessarily alwa ...

  5. 通过live555实现H264 RTSP直播

    http://blog.csdn.net/firehood_/article/details/16844397

  6. android studio 偶记

    修改项目名称 如果仅仅改了文件夹的名字,则会出现引用问题,相应的如下文件都要做相应的修改: 1. package name 要做相应调整 2. settings.gradle ,中要修改相应的moda ...

  7. 原生态Ajax实例

    <script type="text/javascript"> var xmlhttprequest; function GetXmlHttpRequest() { i ...

  8. 【CF】142 Div.1 B. Planes

    SPFA.注意状态转移条件,ans的求解需要在bfs中间求解.因为只要到了地点n,则无需等待其他tourist.还是蛮简单的,注意细节. /* 229B */ #include <iostrea ...

  9. 【转】win7 虚拟机virtualbox中ubuntu12.04安装samba实现文件共享

    原文网址:http://blog.csdn.net/watkinsong/article/details/8878786 昨天心血来潮,又装了个虚拟机,然后安装了ubuntu12.04,为了实现在虚拟 ...

  10. SharePoint 2010中使用SPListItemCollectionPosition更快的结果

    转:http://www.16kan.com/article/detail/318657.html Introduction介绍 In this article we will explore the ...