10 examples of 'get html from url' in JavaScript

Every line of 'get html from url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
68function getHTMLFromUrl(url, cb) {
69 request(url, function(error, response, body) {
70 if (!error && response.statusCode == 200) {
71 var data = {
72 html: body,
73 url: url,
74 headers: response.headers
75 };
76 cb(null, data);
77 } else {
78 cb(error, null);
79 }
80 });
81}
30function getHTMLContent(url){
31 if((url.trim() === "") || (url.indexOf("http://") === -1) || (url.replace("http://", "").trim() === "")) {
32 alert("Insert a valid URL. It has start with \"http://\".");
33 started = false;
34 t = 0;
35 return;
36 }
37
38 url = url.trim();
39
40 loaded = document.getElementById('loaded');
41 loaded.style.background = "red";
42 loaded.style.borderColor = "darkred";
43 loaded.innerHTML = "<h1>Loading the HTML of <a target="\&quot;_blank\&quot;" href="&quot; + url + &quot;">" + url + "</a><div></div></h1>"
44 timOut = document.getElementById('timOut');
45 started = true;
46
47 $.ajax({
48 url: url,
49 type: 'GET',
50 success: function(res) {
51 var headline = res.responseText;
52 if(headline === ""){
53 loaded.innerHTML = "<h1>There was a problem with the page. Be sure that your url is correct.</h1>";
54 return;
55 }
56
57 htmlCodeTextArea.value = headline;
58 loaded.style.background = "green";
59 loaded.style.borderColor = "darkgreen";
60 started = false;
61 loaded.innerHTML = "<h1>Successfully loaded HTML code of <a target="\&quot;blank\&quot;" href="&quot; + url + &quot;">" + url + "</a></h1>";
62 }
63 });
64}
12function getContent(url) {
13 const el = document.querySelector(`.webResource[data-url="${url}"]`);
14 return el ? el.innerHTML : null;
15}
27function isHtmlUrl(url) {
28 return url.indexOf('.html', url.length - 5) != -1
29}
41public static getPage(url: string): string {
42 let urlParts = url.split('/');
43 return urlParts[(urlParts.length - 1)];
44}
27async getLink(url) {
28
29 const { httpRequest, cheerio } = this.libs;
30
31 let html = await this.checkLive(url);
32
33 if( html == false ) throw new Error("LINK DIE");
34
35 let $ = cheerio.load(html);
36 let sources = [];
37 let temp = [];
38
39 $("video source").each(function() {
40 var label =
41 $(this).attr("type") !== "video/mp4"
42 ? "NOR"
43 : $(this).attr("res") === "854x480" ? "480p" : "360p";
44
45 temp.push({
46 label: label,
47 file: $(this).attr("src"),
48 type: "embed"
49 });
50 });
51
52
53 let arrPromise = temp.map(async function(val) {
54
55 let isDie = await httpRequest.isLinkDie(val.file);
56
57 if( isDie != false ) {
58 val.size = isDie;
59 sources.push(val);
60 }
61 });
62
63 await Promise.all(arrPromise);
64
65 return {
66 host: {
67 url: url,
68 name: "estream"
69 },
70 result: sources
71 }
72}
62function __getURL(url) {
63 url = __getURLNoCDN(url);
64 // only relative urls
65 if (__paths.CDN &amp;&amp; /^\\\/[^\\\/]/.test(url)) {
66 url = __paths.CDN + url;
67 } else if (__paths.S3CDN) {
68 url = url.replace(__paths.S3BaseUrl, __paths.S3CDN);
69 }
70 return url;
71}
562function getUrlContent(url)
563{
564 try {
565 var xhr = new XMLHttpRequest();
566 xhr.open("GET", url, true);
567 xhr.onreadystatechange = function()
568 {
569 try {
570 if (this.readyState == 4) {
571
572 console.log("got page. extracting img url");
573
574 imgurl = extractPageImg(this.responseText, url);
575
576 this.abort();
577 }
578 } catch (e) {
579 console.error(e.message);
580 }
581 }
582
583 xhr.send();
584 } catch (e) {
585 console.error(e.message + bookmark.url);
586 }
587}
15function get_data(url){
16
17 dir = url.split('/');
18 console.log("URL : "+ url);
19 var data = undefined;
20
21 for(var i in dir){
22 data = ds[dir[i]];
23 if(data == undefined) break;
24 }
25
26 return data;
27}
2function getParsedURL() {
3
4 var node_url = document.getElementById('id_input_url');
5
6 var parser = document.createElement('a'),
7 searchObject = {},
8 queries, split, i;
9
10 // Let the browser do the work
11 parser.href = node_url.value;
12
13 // Convert query string to object
14 queries = parser.search.replace(/^\?/, '').split('&amp;');
15 for( i = 0; i &lt; queries.length; i++ ) {
16 split = queries[i].split('=');
17 searchObject[split[0]] = split[1];
18 }
19
20 return {
21 protocol: parser.protocol,
22 host: parser.host,
23 hostname: parser.hostname,
24 port: parser.port,
25 pathname: parser.pathname,
26 search: parser.search,
27 searchObject: searchObject,
28 hash: parser.hash
29 };
30}

Related snippets