Node.js渗透重复结果
Node.js Osmosis Repeating Results
我正在使用Osmosis进行刮擦。
下面是我为抓取Bing搜索结果而写的例子:
var osmosis = require('node-osmosis');
var keyword = "download game"
osmosis.get('http://www.bing.com/search?q='+keyword) // url of the site you want to scrape
.find('//*[@id="b_results"]/li/div[2]/p') // selector
.set('info') // name of the key in the results
.find('//*[@id="b_results"]/li/div[1]/h2')
.set('title')
.find('//*[@id="b_results"]/li/div[1]/h2/a/@href')
.set('link')
.data(function(results) { //output
console.log(results);
});
我遇到的问题是,当我运行此代码时,它对每个项目都会重复结果(10次!)。
像这样的东西:
{ title: 'GameHouse - Official Site',
link: 'http://www.gametop.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.download-free-games.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.myplaycity.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://download.cnet.com/windows/games/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.gametop.com/category/downloadable.html' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.shockwave.com/download.jsp' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.myplaycity.com/games/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'https://www.games.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'https://www.gamehouse.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'GameHouse - Official Site',
link: 'http://www.games2download.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.gametop.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.download-free-games.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.myplaycity.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://download.cnet.com/windows/games/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.gametop.com/category/downloadable.html' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.shockwave.com/download.jsp' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.myplaycity.com/games/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'https://www.games.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'https://www.gamehouse.com/' }
{ info: 'Searching for safe and virus-free Game Downloads to play? Our site is packed with downloadable games in a variety of genres, download the Free Versions and have …',
title: 'Games 2 Download - 1000 virus-free …',
link: 'http://www.games2download.com/' }
我想知道如何解决这个问题。谢谢
我可能错了,但我的猜测是,当你找到一个元素时,它会乘以出现的次数。
假设你有两个元素要设置。第一个元素CCD_ 1,并且它找到了3个匹配项。并且第二元素CCD_ 2找到2个匹配。
你将得到的行数是6。
相关文章:
- 奇怪的Javascript结果
- Javascript(jQuery)给了我奇怪的结果
- JSONP请求返回结果,但也触发error_callback
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Javascript,输出结果后页面不断刷新
- 这是使用html快照和谷歌获取的预期结果吗?SEO/SPA
- 将地理编码结果转换为php变量以发布到mysql数据库
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- JQuery:向多个匹配结果添加换行符的最简单方法
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- webpack代码拆分了handlerbs文件——结果是文件很大
- JavaScript循环无法正确计算/显示结果
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- Node.js使用Series函数(模式?)实现流控制时出现意外结果
- 试图将onChange函数作为道具传递给GrandChlidren,结果是TypeError:这是未定义的
- jQuery使用api获取typeform结果
- 根据条件检查数据库结果
- 什么'这是从第三个函数上的async 1st函数获得结果的更好方法
- Angular,表达式{{}}的结果没有插入到ng-click中
- Node.js渗透重复结果