2016-07-31 35 views
-3

有沒有辦法在jquery中選擇包含href或鏈接文本中的某個單詞的所有鏈接? (兩者都是同一個詞)?請評論一種選擇cheerio可以解釋的方式,我使用NPM中的節點和cheerio創建一個需要遍歷頁面上所有鏈接的刮板,並查找「襯衫」是鏈接本身還是文本內部與鏈接有關。然後,我需要爲任何這些鏈接請求HTML,併爲特定數據進行刮擦。謝謝jQuery和cheerio,選擇在href或文本中包含單詞的鏈接?

回答

0
$('a').each(function() { // Go through all links 
    if ($(this).text() == "LINK TEXT") { // Change text to whatever you want to compare 
     // Do what you want with links having certain text 
    } 
    if ($(this).attr("href") == "HREF VALUE") { // Change href to whatever you want to compare 
     // Do what you want with links having certain href 
    } 
}); 

這將檢查指定文本和/或href的所有鏈接。

相關問題