问题
I'm looking to scrape the links of post shown on facebook feed. I noticed that post link has two things in common it has https://www.facebook.com/username/posts/1234567890
https://www.facebook.com/ and /posts/ is always there.
I used this code to get all links on the page but I don't know how to only grab links with
https://www.facebook.com/ and /posts/ in this.
var links = document.querySelectorAll("a[href^='https://www.facebook.com']");
for(var i = 0; i< links.length; i++){
console.log(links[i].href);
}
I tried regex and this is what I found after learning regex for this url pattern
^(https://www.|http://)[a-zA-Z0-9!_$]+.[a-zA-Z]+/[a-zA-Z0-9]+/posts/[0-9]+$
but I don't know how to use this to get the result.
can anyone please help me with this?
来源:https://stackoverflow.com/questions/64517282/how-to-scrape-links-from-a-webpage-using-javascript