[Node.js] Web Scraping with Pagination and Advanced Selectors
2023-09-14 08:59:20 时间
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" } ] * */
相关文章
- js 正则是否包含某些字符串_js判断字符串是否包含某个字符串「建议收藏」
- 初识js中的闭包_Js闭包中变量理解
- 【说站】js中every方法怎么用?
- 图解 Node.js 的核心 event-loop
- Memlab,一款分析 JavaScript 堆并查找浏览器和 Node.js 中内存泄漏的开源框架
- Express 基于 Node.js 平台,快速、开放、极简的 Web 开发框架
- Node.js安装
- Node.JS中调用JShaman接口,实现JS代码加密
- 建立一个node.js服务器(使用express搭建第一个Web环境)详解编程语言
- ThinkJS 3 正式版发布,Node.js Web 框架详解编程语言
- Linux上部署Node实现更多功能(linux安装node)
- Linux环境下配置Node.js(linux配置node)
- 数据Node.js实现MySQL数据的同步更新(node同步mysql)
- Node.js 4.0.0 正式发布了
- 数据库操作快速入门:Node.js中MySQL数据库操作(nodejs的mysql)
- WordPress 4.3 将用 Node.js 重写
- 利用Node.js实现对MS SQL服务器的连接(node连MSsql)
- 利用Node.js封装MSSQL的尝试(node mssql封装)
- JS面向对象之神奇的prototype
- js判断鼠标同时离开两个div的思路及代码
- JS网页播放声音实现代码兼容各种浏览器
- js截取小数点后几位的写法
- javascript(js)的小数点乘法除法问题详解
- 2014年最火的Node.JS后端框架推荐
- node.js中的buffer.Buffer.isBuffer方法使用说明
- node.js中的buffer.fill方法使用说明
- node.js中的fs.writeFile方法使用说明
- node.js中的fs.truncateSync方法使用说明
- js在数组中删除重复的元素自保留一个(两种实现思路)