Advertisement
riskey95

Scrape Wiki

Jun 10th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var moment = require('moment');
  2. var clarinet = require("clarinet")
  3.   , parser = clarinet.parser();
  4. var request = require("request"),
  5.   cheerio = require("cheerio");
  6.  
  7. var mm = moment().locale("id")
  8. var text1 = "Peristiwa Sejarah\n"+mm.format("DD MMMM");
  9.  
  10. function peristiwaHariIni(){
  11.     var url = "http://id.wikipedia.org/wiki/"+mm.format("DD_MMMM");
  12.     console.log(url);
  13.     request(url, function (error, response, body) {
  14.         if (!error) {
  15.             var $ = cheerio.load(body);
  16.             $('#Peristiwa').parent().next().find('li').each(function(){
  17.                 item.push({        
  18.                     "content": $(this).text()
  19.                     });    
  20.             });
  21.             parser.write(JSON.stringify(item)).close();    
  22.         } else {
  23.             console.log("We’ve encountered an error: " + error);
  24.         }
  25.     });
  26.     parser.onvalue = function (v) {
  27.         text1 += v+"\n";       
  28.     };
  29.     return text1;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement