I’ve run into numerous situations where I need to loop through data on a website that I do not own (typically API documentation) so that I can reformat it and make it usable. For example, AWS Route 53 includes a list of top-level domains (TLDs) in a page with related data for each TLD but it’s in an HTML format. You can use JavaScript by default in the chrome console but jQuery allows me to create these one-off scripts more quickly.
Step 1: Copy the code below
Load jQuery into your current page by copying and pasting the following code into your Chrome Console.
var jqry = document.createElement('script');
jqry.src = "https://code.jquery.com/jquery-3.3.1.min.js";
document.getElementsByTagName('head')[0].appendChild(jqry);
jQuery.noConflict();
It may take a bit of time for jQuery to load. But, once jQuery is loaded, you can run your custom jQuery functions in chrome console. There may be some conflicts with other jQuery versions that may have been loaded on the page.
Step 2: Paste the code in your Browser’s Console
If you don’t know how to get to your browser’s console, make sure you right click on the page that you want to scrape and click on Inspect.
Then, click on the Console tab, paste the code that you copied above it into the console, and click enter to run the code. It’ll look like the picture below:
TRY IT OUT
We love using SubtlePatterns.com for classy and cool website backgrounds. Go try out this script on SubtlePatterns.com and it’ll kick you back all the URLs for all the background patterns on that page.
Remember you need to be using Chrome, and then open the console and paste this in and hit enter, it’s that simple!!
var jqry = document.createElement('script');
jqry.src = "https://code.jquery.com/jquery-3.3.1.min.js";
document.getElementsByTagName('head')[0].appendChild(jqry);
jQuery.noConflict();
PRESS ENTER.
You need to press enter to execute the javascript in the browser and add jQuery to the web page in Chrome.
Finally, enter the following code to get all the subtle patterns on a page.
let thumbs = []
$('.patternpreview').each(function() {
thumbs.push($(this).css('background-image').replace('url("', '').replace('")','')) })
console.log(thumbs);
The results should look something like this: