JavaScript Code Library
convenient for code write
获得当前网页元素上的所有的链接
Method 1 (short)
1
2
3[...new Set(Array.from(document.querySelectorAll('[src],[href]')).map(i=>i.src||i.href))]
[...new Set(Array.from($$('[src],[href]')).map(i=>i.src||i.href))]
// ...剥衣;new Set去重;$$=document.querySelectorAllhuman-readable
1
2
3
4
5
6
7
8
9let urls = []
$$('*').forEach(i => {
urls.push(i.src)
urls.push(i.href)
urls.push(i.url)
});
console.log(...new Set(urls))
//(*) means all elementshuman-readable( with regex )
1
2
3
4
5
6
7
8
9
10
11let urls = []
$$('*').forEach(i => {
urls.push(i.src)
urls.push(i.href)
urls.push(i.url)
});
regexUrls= $.grep(urls, function (n) {
try {return n.match(/.*http://XXX.COM.*/i)} catch (e) {}
}); console.log(...new Set(regexUrls))
// http://XXX.COM. change to your search target