2017-06-28 10 views
0

私は自分のWeb Scrapperをウェブサイト(https://hypebeast.com/footwear)から各記事のタイトルを引っ張ってみようとしていますが、未定義のものや本当に乱雑なものは得られません。私は間違って何をしていますか?ここに私のコードの抜粋です:NodeJSとCheerioを使ったWebの掻き取り

 const request = require('request'); 
     const cheerio = require('cheerio'); 

     var titles = []; 

     request('https://hypebeast.com/footwear', function(err, resp, body) { 
      var $ = cheerio.load(body); 
      $('.title').each(function(){ 
       var title = $(this).attr('span'); 
       titles.push(title); 
      }); 

      console.log(titles); 

     }); 

ここでエラーがあります:ないチェリオの読み取り問題で http://imgur.com/chB9v6h

+0

あなたのエラーを表示してください: だからあなたがそうのようなスクリプトを使用する必要が何かを見つけることができます。 – Aswin

答えて

0

これ。 私はウェブサイトを開き、DOM構造が異なることがわかります。

const request = require('request'); 
 
     const cheerio = require('cheerio'); 
 

 
     var titles = []; 
 

 
     request('https://hypebeast.com/footwear', function(err, resp, body) { 
 
      var $ = cheerio.load(body); 
 
      $('.title').each(function(){ 
 
       var title = $(this).children("h2").children('span').text(); 
 
       titles.push(title); 
 
      }); 
 

 
      console.log(titles); 
 

 
     });

+0

ああ、ありがとう、今働く:) – newang

関連する問題