Solution of : =IMPORTHTML() Errors : Could not fetch url

Here's a sample custom function to import any table from web page HTML.
Copy the code into the Tools > Script Editor.
The Code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function importTable(URL,i) { | |
//Content | |
var resp=UrlFetchApp.fetch(URL).getContentText(); | |
//Regex | |
var regT=/<table[^>]*>([\s\S]*?)<\/table[^>]*>/g; | |
var regR=/<tr[^>]*>([\s\S]*?)<\/tr[^>]*>/g; | |
var regC=/<t[^>]*>([\s\S]*?)<\/t[^>]*>/g; | |
//Get All Tables | |
var tables=resp.match(regT).map(function(val){ | |
return val.replace(/<\/?table[^>]*>/g,''); | |
}); | |
//Get Table in rows | |
var rows=tables[i].match(regR).map(function(val){ | |
return val.replace(/<\/?tr[^>]*>/g,''); | |
}); | |
//Fill Array | |
var arr=[]; | |
for(var r in rows){ | |
arr.push([]); | |
var row=rows[r].match(regC).map(function(val){ | |
return val.replace(/<\/?t[^>]*>/g,''); | |
}); | |
for(var c in row){ | |
arr[arr.length-1].push(row[c].replace(/<\/?[^>]*>/g,'')) | |
} | |
} | |
return arr; | |
} |
Sample :
worked like a champ! thanks for sharing 5/2019
ReplyDeleteThank you for comment
Deletenot working showing
ReplyDeleteDNS error: http://undefined (line 4, file "Code")Dismiss
Hi, Can you send me your code
DeleteSame problem plz help code is same which you peast
Deletei want table from https://www1.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=-10006&symbol=NIFTY&symbol=NIFTY&instrument=-&date=-&segmentLink=17&symbolCount=2&segmentLink=17
ReplyDeleteplease help me