RChris
07-03-2007, 04:22 PM
Hello everyone,
I was wondering if anyone could help me please. I want to read the html code from a url and store it into a string, but I don't know how to go about it. Any help would be greatly appreciated.
So far what I have done is this function, which loads the Google search results on a page. I have a lot of other code that helps in loading the Google search page from a text box. My aim is to retrieve all the html code after doing a google search and store it in a long string (adding each line, one after another).
function search(){
var url = "";
var searchTermsBox = document.getElementById("input");
URL = "http://www.google.com/search?q=" + searchTerms;
LoadURL(URL);
}
I tried using xmlhttprequest() object, but am not sure how to use it.
***********************
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200)
dump(req.responseText);
else
dump("Error loading page\n");
};
req.send(null);
alert (req);
}
var resultsgroup = req;
//var resultsgroup = document.getElementById ("res");
alert ("resultsgroup"+resultsgroup);
*******************
basically what I want to do is just retrieve the html source code from a web page and store it in a string. I could use the stream reader to concatenate and store the stream as a string. Not sure how to go about it though.
I realise all the code above may be confusing, but you can ignore it if you want and suggest some ideas.
Thank you
I was wondering if anyone could help me please. I want to read the html code from a url and store it into a string, but I don't know how to go about it. Any help would be greatly appreciated.
So far what I have done is this function, which loads the Google search results on a page. I have a lot of other code that helps in loading the Google search page from a text box. My aim is to retrieve all the html code after doing a google search and store it in a long string (adding each line, one after another).
function search(){
var url = "";
var searchTermsBox = document.getElementById("input");
URL = "http://www.google.com/search?q=" + searchTerms;
LoadURL(URL);
}
I tried using xmlhttprequest() object, but am not sure how to use it.
***********************
var req = new XMLHttpRequest();
req.open('GET', url, true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200)
dump(req.responseText);
else
dump("Error loading page\n");
};
req.send(null);
alert (req);
}
var resultsgroup = req;
//var resultsgroup = document.getElementById ("res");
alert ("resultsgroup"+resultsgroup);
*******************
basically what I want to do is just retrieve the html source code from a web page and store it in a string. I could use the stream reader to concatenate and store the stream as a string. Not sure how to go about it though.
I realise all the code above may be confusing, but you can ignore it if you want and suggest some ideas.
Thank you