javascript - Get select table contents using Greasemonkey -
i'm trying retrieve contents of table, site, using greasemonkey script. here's how table looks:
<table class="ocalaisbox"> <tr class="ocalaisheadrow"> <td colspan="4" class="ocalaistitlebar">topics in article</td> </tr> <tr> <td class="ocalaislist indexnormaltext"> <div class="ocalaisheader">country</div> <ul> <li><a href="/category/country/nigeria">nigeria</a></li> <li><a href="/category/country/bosnia-and-herzegovina">bosnia , herzegovina</a></li> </ul> </td> </tr> </table> i want retrieve, say, "nigeria" , "bosnia , herzegovina".
editor's note: here's live page structure.
since want list of countries in article, easiest bet key off of link hrefs provided. other answers' approaches work sample html, fetch whole lot of other stuff on the actual page (sample).
the simplest (readable) code:
//--- country links: var cntrylinks = document.queryselectorall ("a[href^='/category/country/']"); //--- extract country names: var namelist = [].map.call (cntrylinks, function (clink) { homecoming clink.textcontent; } ); //--- convert text: var countrystr = namelist.join (", "); //--- display: console.log ("countries: " + countrystr); alert ("countries: " + countrystr); keep in mind that site puts info on (most) news articles, not pages.
javascript html greasemonkey
No comments:
Post a Comment