Help need on extracting links from a webpage

I'm trying to extract links from a webpage and having some difficulties hope someone can help. Below is the test Macro: open a page, extract all links and display them. However when I ran it the webpage opens but there is no link displayed.

For the javascript code, I also tried below but got same result (no link displayed).

Array.from(document.links, x => x.href).filter(e => e.match(/html$/i)).join('\n');

How to debug and make this work? ("Allow JavaScript from Apple Events" has been checked in Safari setting). Thanks.

process links Macro (v11.0.2)

process links.kmmacros (4.1 KB)

Try this in your Javascript action

return Array.from(document.links, x => x.href).filter(e => e.match(/html$/i)).join('\n');
1 Like

Awesome this works, thank you!

1 Like

A word to the wise:

Lateral scanning (left to right) imposes cognitive processing effort on the reader, and long lines get occluded by the forum software.

( Vertical scanning is easier for your eyes than horizontal work )

No kudos for "one-liners" :slight_smile:

You can reduce the processing effort, for yourself, and for your readers,
by using horizontal expansion very sparingly:

return Array.from(document.links, x => x.href)
.filter(e => e.match(/html$/i))
.join('\n');
2 Likes