2016-04-21 73 views
0

我想爲我的調查提取印度所有政府網站的列表。使用查詢從網站提取鏈接

名單這裏找到: http://goidirectory.nic.in/index.php

的這裏的問題是,該名單是不是在鏈接的形式。每當我需要打開一個網站時,它會打開一個新標籤,然後從那裏重定向到所要求的網站。

因此,谷歌klipper和其他工具從網站提取鏈接不起作用。

我對JavaScript沒有任何瞭解。

有一兩件事我注意到的是,當我把鼠標指針指向的鏈接它顯示的網站鏈接的名稱,如下圖所示:

Mouse pointer

像如http://presidentofindia.gov.in進來的亮點。

我需要這樣的網站的鏈接列表

感謝

回答

1

嗨請檢查https://jsfiddle.net/9b0wL9tn/

jQuery的

$(document).ready(function(){ 
    $('a').each(function(){ 
    console.log($(this).attr('href')); 
}); 
}); 

注意:在Chrome中打開網站>>右鍵點擊>>檢查>>轉到控制檯選項卡並粘貼以下內容並按下回車鍵

運行該代碼首先在控制檯上:

var jq = document.createElement('script'); 
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"; 
document.getElementsByTagName('head')[0].appendChild(jq); 
// ... give time for script to load, then type. 
jQuery.noConflict(); 

然後運行這個

$('a').each(function(){ 
     console.log($(this).attr('href')); 
}); 

這會列出該網頁上的所有鏈接只是把它從控制檯

更新複製

家繼上一個步驟後更新腳本...在控制檯中運行以下腳本:

var arr=new Array(); 
jQuery('a').each(function(i){ 


arr[i]=jQuery(this).attr('title')+""; 


}); 

jQuery.each(arr,function(i){ 
if(arr[i].indexOf('http')>-1) 
console.log(arr[i].substr(0, arr[i].indexOf('-'))); 
}); 

這裏是截圖:http://www.imageno.com/lj7tuyr9pt2opic.html

+0

當我粘貼後的代碼到控制檯,並按下回車,我(...)(匿名函數)@ VM214:2InjectedScript._evaluateOn @ VM90:878InjectedScript._evaluateAndWrap @ VM90:811InjectedScript.evaluate @@ VM904: VM90:667「 – prakharjain

+0

也許這是因爲該網站使用jQuery – RRR

+0

或將此擴展程序添加到您的Chrome https://chrome.google.com/webstore/detail/jquerify/gbmifchmngifmadobkcpijhhldeeel kc?hl = en – RRR