2012-05-22 12 views
0

我有物種的名單在這裏:發現兩個網頁的常用詞在飛行

http://megasun.bch.umontreal.ca/ogmp/projects/other/compare.html

這裏的物種清單:

http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=3524

我想找到在BOTH頁面上提及的所有物種。我該如何快速做到這一點? (我不介意是否找不到有關物種的詞彙,我想做比較一般的詞彙:)

感謝您的建議。

+0

用什麼語言?你試過什麼了? – knittl

回答

0

在在控制檯的每一頁,這樣做:

var html = document.body.innerHTML; 
results = []; 
html.match(/>([^<]+?)</g)    // grab all values like ">...<" 
    .map(function(match) {    // look for a long words..words..words 
     return match.match(/\w.*\w/); 
    }) 
    .filter(function(match) {   // ignore empty matches 
     return match!==null 
    }) 
    .forEach(function(match) { 
     var text = match[0]; 
     if (!text.match(/[0-9]/) &&  // ignore matches with numbers 
      results.indexOf(text)==-1) // add to results if not duplicate 
      results.push(text); 
    }); 
JSON.stringify(results); 

然後做:

var page1 = JSON.parse(' /*COPY-PASTE THE RESULT OF PAGE 1*/ '); 
var page2 = JSON.parse(' /*COPY-PASTE THE RESULT OF PAGE 2*/ '); 
page1.map(function(s){return page2.indexOf(s)!=-1}); 

這是必要的,以規避瀏覽器的限制。

演示:

> JSON.stringify(page1.filter(function(s){return page2.indexOf(s)!=-1})) 
'["Beta vulgaris","Spinacia oleracea"]'