Skip to main content

How to Scrape Images using Javascript || How to Scrape Hyperlink using Javascript

Intro:- Suppose you are visiting some site or social media, or forum or blog, and you just come by bunch of images which is really awesome. And you want all the URL of the Image or Hyperlink. For this you don't need to install any software or Plugin. Its just simple old trick in javascript.

How does it work?

Simple Just run the JavaScript code and It will collect all the data in a text file and ask where you want to it.
*Note: It will save it in a text file but you need to open using Notepad++ to View Proper Line Break Formatting.

Step 1: Open Developer Tool in your Browser. i.e. Press  Ctrl + Shift + I will work on both Mozilla and Chrome.

Step 2: Click on Console Tab.

Step 3: And Paste the following code and Run. (In Mozilla Firefox you might have to type allow pasting in console to paste.)

Step 4: Choose What You want to Run

A] To Get Images URL [Paste and Run this Code.]

// Scrape ALL IMAGES From ANY WEBSITE & HTML
// img => src
var links = document.querySelectorAll('img');
var linksArray = [];
for (var i = 0; i < links.length; i++) {
    // Store links in variable
    linksArray.push(links[i].src);
    // Works fine in console
    console.log(linksArray);
  }

// Create text document — only saves 1st link in text doc
  var textDoc = document.createElement('a');

  textDoc.href = 'data:attachment/text,' + encodeURI(linksArray.join('\n'));
  textDoc.target = '_blank';
  textDoc.download = 'Image_file.txt';
  textDoc.click();

B] To Get Hyperlinks URL [Paste and Run this Code.]

// Scrape ALL Hyperlink From ANY WEBSITE & HTML
// a => href
(function() {
  var links = document.querySelectorAll('a');
  var linksArray = [];
  // Loop through all links
  for (var i = 0; i < links.length; i++) {

    // Store links in variable
    linksArray.push(links[i]);

    // Works fine in console
    console.log(linksArray);
  }

  // Create text document — only saves 1st link in text doc
  var textDoc = document.createElement('a');

  textDoc.href = 'data:attachment/text,' + encodeURI(linksArray.join('\n'));
  textDoc.target = '_blank';
  textDoc.download = 'Hyperlink_file.txt';
  textDoc.click();

  })();


Scrape using Javascript

Views:

Comments

Back to Top

Popular posts from this blog

How to get View Count in every single page in blogspot / blogger?

Before we start let me answer some of your following questions that you might be thinking...   Q. What is "View Count" anyways? Ans. With View count you can keep track on how many people have visited your blog site with a total number of counts displayed in your blog. It also gives you a better idea how many people are coming to your blog daily. Q. Blogspot / Blogger already has this feature so what so special about this tutorial? Ans. Yes, I agree blogspot does have this feature and its great no coding involved but you cannot do this... Suppose you have made 2 posts: Page A, Page B. Whatif you want to know how many people visited Page A Vs Page B. Suppose people visited Page A - 100 times and Page B - 5 times. Blogspot View Count will show you only total visits i.e. 105 visits. And not for Page A or Page B specifically.  So to see Views for Each page... this is how to I did. Just copy paste this code on your blogspot page and you are good to go. <!--- //////////...

[SOLVED] Google-served ads on screens without publisher-content

Waiting for Approval? And you get a mail something like this? ========================================= Your Publisher ID: pub-123456789 Sign In Thanks for submitting your site "<Your_WebSite.com>" for AdSense. The team has reviewed it but unfortunately your site isn’t ready to show ads at this time. There are some issues which need fixing before your site is ready to show ads. For more information, visit the ' Sites ' page in your account. You can find more details and application tips in the below video : We encourage you to review and update your site. Once you’ve done so, you can request a review. Our specialists will review your site for compliance with our Program policies , so make sure to resolve all of the issues. Watch our ' AdSense Site Approvals ' video series to troubleshoot your policy issues and start earning money from your site. Go to Sites ...

How to Add Likes and Views Button in Blogspot?

Here I am going to show you a simple trick which can be used to keep track on every views plus add a like button with various customize options. But first lets just dive into the code. Instead of going into Layout we are going to paste this code in our Post Itself. Just change Compose View to HTML View & Paste it under your post content. This Code is for View Counter (Blogspot also has its own widget called Blog's Stats in Add a Gadget option. But it will not show you View Count on Each Post / Pages. But this code will. ) <!-- View Counter BEGIN --> <script> window .onload = function () { var xhr = new XMLHttpRequest(); var url = window .location.href.replace( "https://" , "" ).replace( /\//g , "" ); var urlr = url.substring( 0 , 53 ); //document.getElementById("demo").innerHTML = urlr; xhr.open( "GET" , "https://api.countapi.xyz/hit/" +urlr); x...