HTML to string JS

Shoop

Newbie
Joined
Apr 22, 2015
Messages
1
Reaction score
0
Heya all, so ive run into a problem with my scripting knowledge.
I need some help with turning a website into an html. to be more specific, im wondering how to give URL to the script and that it turns the website from the URL into a string. as im a bit new in JS, im having a hard time understanding XMLHttpRequest and how to execute it compleatly. Ive found and read some examples but they are all outdated and dont work. and reading up on url-that-i-cant-post is bit hard o me cos i dont understand much of it.


to give a more specific problem, i need to input an URL and save the html in a string. later i can, and know how to, extract the data that i need from it, but im stuck on the problem of saving it as a string.

using win8.1 and FF, other OS-es are not an option, and i would prefer to keep using FF
If you do have any queestions feel free to ask, ill try to respond asap

regards,
Shoop
 
Code:
document.getElementsByTagName('html')[0].innerHTML

Instead of the document object, you use the variable where you put the response of your http request.

So if you did this:

Code:
function getWebsite(url)
{
     var xmlHttp = new XMLHttpRequest();
     xmlHttp.open( "Get", url, false ); // Uses GET to download the website. 
     xmlHttp.send( null );
    return xmlHttp.responseText;
}

var website = getWebsite('url');
website.

This would be easier in PHP though and faster imo. Javascript uses the client to process stuff like this. So processing speed will depend on the client. If you grabbed the info with Js then pushed it to PHP, the php does all the processing.

Also having it process information on the client side opens your site up to alot of exploits.
 
Last edited:
Heya all, so ive run into a problem with my scripting knowledge.
I need some help with turning a website into an html. to be more specific, im wondering how to give URL to the script and that it turns the website from the URL into a string. as im a bit new in JS, im having a hard time understanding XMLHttpRequest and how to execute it compleatly. Ive found and read some examples but they are all outdated and dont work. and reading up on url-that-i-cant-post is bit hard o me cos i dont understand much of it.


to give a more specific problem, i need to input an URL and save the html in a string. later i can, and know how to, extract the data that i need from it, but im stuck on the problem of saving it as a string.

using win8.1 and FF, other OS-es are not an option, and i would prefer to keep using FF
If you do have any queestions feel free to ask, ill try to respond asap

regards,
Shoop


http://www.accessify.com/tools-and-wizards/developer-tools/html-javascript-convertor/
This is a free converter :)
 
I know this was posted awhile ago, but I just wanted to say that function '''' getWebsite(url) ''' is super cool. I didn't know that object existed.
 
Back
Top