Advertisement
Heruberuto

getData.js

Jan 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Herbert on 25.01.2016.
  3.  *
  4.  * Open webpage https://en.wikipedia.org/wiki/List_of_state_leaders_in_2015 with disabled images (for better performance),
  5.  * copy-paste this script to browser console, after about 600 seconds, all parsed names and birth dates should be stored
  6.  * in global variable allBorn
  7.  */
  8. var $selector=$("#mw-content-text > ul > li > ul > li > a:nth-child(1)," + "#mw-content-text > ul > li > ul > li > ul > li > a:nth-child(1)," + "#mw-content-text > ul > li > ul > li > ol > li> a:nth-child(1)"),
  9.     bornSelector="tr:has(th:contains('Born')) td";
  10.  
  11. var win = document.defaultView || this.ownerDocument.parentWindow, repeat=true,repeated=false,allBorn="",i=0;
  12. $selector.each(function(){
  13.     var $a=$(this);
  14.     setTimeout(function() {
  15.         if(!repeat&&repeated){
  16.             return;
  17.         }else{
  18.             repeated=true;
  19.         }
  20.  
  21.             var url="https://en.wikipedia.org"+$a.attr("href");
  22.             if (win == window) {
  23.                 var $newWindow=$("<iframe></iframe>");
  24.  
  25.                 $newWindow.appendTo('body');$newWindow.css({
  26.                     'position':'fixed',
  27.                     'width':'100%',
  28.                     'height':'700px',
  29.                     'top':0,
  30.                     'left':0,
  31.                     'z-index':100+(i)
  32.                 });
  33.                 $newWindow[0].contentWindow.location.href=url;
  34.                 $newWindow.on('load',function(){
  35.                     var $contents=$newWindow.contents();
  36.                     var $bornRef=$contents.find(bornSelector);
  37.                     var $bDay=($bornRef.length!=0)?$bornRef.find(".bday"):[];
  38.                     var $born=($bDay.length!=0)?$bDay.text():[];
  39.                     var $name=$contents.find("#firstHeading").text();
  40.                     if($born.length<128 && $born.length>0){
  41.                         allBorn+=$name+"::"+$born+";;;;";
  42.                     }
  43.  
  44.                     $newWindow.unbind('load');
  45.                     $newWindow.remove();
  46.                 });
  47.             }
  48.     }, (i++)*1000);
  49.  
  50. });
  51. setTimeout(function() {console.log(allBorn)},6000);
  52. setTimeout(function() {console.log(allBorn)},40000);
  53. setTimeout(function() {console.log(allBorn)},(i)*1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement