I'm trying to scrape the first paragraph from wikipedia using only javascript. Basically, what I want to do is
document.getElementsByTagName("P")[0]
except it's not on my web page, I want to fetch a given page from wikipedia and apply that functionality. My current codes gives:
Uncaught TypeError: undefined is not a function
My code:
function getWikiDescription(searchTerm)
{
var theURL = "http://en.wikipedia.org/wiki/" + searchTerm.replace(" ", "_");
var article = null;
$.get(theURL, function(data){
wikiHelper(data);
}, "html");
}
function wikiHelper(data)
{
alert(data);
console.log(data.getElementByTagName("p")[0]);
}
getWikiDescription("godwin's law");
data basically becomes a giant string containing all of the html, but the getElementByTagName function doesn't work. Any help would be appreciated, thanks in advance.