Web Console trick to get all URLs into your clipboard

27 April 2017   0 comments   Web development, JavaScript

This isn't rocket science in the world of Web Development but I think it's so darn useful that if you've been unlucky to miss this, it's worth mentioning one more time.

Suppose you're on a site with lots of links. Like https://www.peterbe.com/plog.
And you want to get a list of all URLs that contain word "react" in the URL pathname.
And you want to get this into your clipboard.

Here's what you do:

  1. Open your browsers Web Console. In Firefox it's Alt+Cmd+K on OSX (or F12). In Chrome it's Alt+Cmd+J.

  2. Type in the magic: copy([...document.querySelectorAll('a')].map(a => a.href).filter(u => u.match(/react/i)))

  3. Hit Enter, go to a text editor and paste like regular.

It should look something like this:


Web Console in Firefox
The example is just that. An example. The cool thing about this is:

The limit is your imagination. You can also do things like copy([...document.querySelectorAll('a')].filter(a => a.textContent.match(/react/i)).map(a => a.href)) and you filter by the links' text.


Your email will never ever be published

Related posts

Best practice with retries with requests 19 April 2017
Fastest Redis configuration for Django 11 May 2017
Related by Keyword:
Be careful with using dict() to create a copy 09 September 2015
When to __deepcopy__ classes in Python 14 March 2012