简体   繁体   中英

General approach for scraping pages with multiple links on them

Tampermonkey noob here. So I have that wrote a script in tampermonkey that finds the table element on the on a page with a table full of links, gets all the href from it, and puts it into an array.

I need to actually go into those links and get some data, then come back to the table page, and go into the next link, etc, repeat until the last link. I dont know how to achieve that since when it goes back to the table of links page from the first link, the script resets and just goes into the first link again.

Thanks,

Edit:

var urls= [];
for (var i= document.links.length; i-->0;){
if (document.links[i].hostname===location.hostname){
    urls.push(document.links[i].href);
}
}    

I want to go in to the links and open each link and get the data from it and come back, then go on to the next link, repeat.

I'm not really sure what you are asking for, but perhaps what you need to use is a loop? Can edit your question to provide source code?

I think the solution to what you are asking is FOR every link in your array (I'm assuming you have an array of links), make a request (perhaps using jQuery's $.get/$.post or similar...) and then do something with the response.

If you want to do something with your responses, push them to an array, and then after your FOR loop is done, operate on the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM