Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 25, 2022 12:45 pm GMT

WebScrapperJS - Get Content/HTML of any website without being blocked by CORS even using JavaScript by WhollyAPI

WebScrapperJS

WebScrapperJS - Get Content/HTML of any website without being blocked by CORS even using JavaScript by WhollyAPI


Website :- https://sh20raj.github.io/WebScrapperJS/

GitHub | Repl.it | Dev.to Article

Grab the CDN or Download the JavaScript File

<script src="https://cdn.jsdelivr.net/gh/SH20RAJ/WebScrapperJS/WebScrapper.min.js" ></script>

To Get HTML Content of Any Website

var url = 'https://google.com/';var html = WebScrapper.gethtml(url);//html of the url will be stored in this variableconsole.log(html);

Intialise own WebScrapper with URL

let MyWebScrapper = new scrapper('https://example.com/');//You can now directly call gethtml() instead of passing a url into it.console.log(MyWebScrapper.gethtml()); //Grab https://example.com/ and print on console

Still you can Use new created scrapper MyWebScrapper for grabbing new URLs. Like

let MyWebScrapper = new scrapper('https://example.com/');//You can now directly call gethtml() instead of passing a url into it.console.log(MyWebScrapper.gethtml()); //Grab https://example.com/ and print on consoleconsole.log(MyWebScrapper.gethtml('https://example.com/')); //Grab https://youtube.com/ and print on console

You can also fetch JSON Using WebScrapperJS

var json = WebScrapper.getjson('https://jsonplaceholder.typicode.com/todos/1');//Return result direct in json formatconsole.log(json);

Try This

Try this on Codepen

Sample Code | Codepen :- https://codepen.io/SH20RAJ/pen/VwrwjXJ?editors=1001

<div id="scrappedcontent"></div><script src="https://cdn.jsdelivr.net/gh/SH20RAJ/WebScrapperJS/WebScrapper.min.js" ></script> <script>  let MyWebScrapper = new scrapper('https://google.com/');//You can now directly call gethtml() instead of passing a url into it.console.log(MyWebScrapper.gethtml()); //Grab https://example.com/ and print on consolevar html = MyWebScrapper.gethtml('https://example.com/');console.log(html); //Grab https://youtube.com/ and print on consoledocument.getElementById('scrappedcontent').innerHTML = html;</script>

See Results Here


Original Link: https://dev.to/sh20raj/webscrapperjs-get-contenthtml-of-any-website-without-being-blocked-by-cors-even-using-javascript-by-whollyapi-42l7

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To