Node.js渗透重复结果

Node.js Osmosis Repeating Results

本文关键字:结果 渗透 js Node      更新时间:2023-09-26

我正在使用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。