grab a page locally from given URL to handle its DOM tree with native JavaScript DOM methods ,without CORS limitations
*how to use*
var url='https://www.phpclasses.org/';
var UP=new UrlCParse(url);
UP.parseUrl('manage');
document.getElementById(UP.getResponse).onload=function(){
alert(e.detail.data.url_img[0].src);//here you can find the parsed data in the e.detail.data object
}
//or a better and sure way:
document.getElementById(UP.getResponse).addEventListener("UrlParsed", function(e){
alert(JSON.stringify(e.detail.data.url_meta));//here you can find the parsed data in the e.detail.data object
}, false);
//or a more simple way
var url='https://www.phpclasses.org/';
var UP=new UrlCParse(url);
UP.parseUrl('manage',response={});
document.getElementById(UP.getResponse).addEventListener("UrlParsed", function(){
alert(JSON.stringify(response.data.url_meta));//here you can find the parsed data in the response.data object
}, false);
for a local use when the url you try to parse is from the same domain as the requester you can avoid the PHP file
usage by specifying true in the constructor as second parameter.
Note that the usage of PHP in the package is mainly to go around the CORS limitations.And thus is very worth when you
want to parse different domain's (from yours) urls.
these are the full list of objects you will find in the data object:
data = {
[url_meta] => {
[name]=>"content",
etc...........
}
[url_title] => "title textnode"
[url_http_equiv] => {http-equiv meta tags}
[url_twitter_meta] => {twitter meta tags}
[url_og_meta] => {open graph meta tags}
[url_h1] => "textnode",
[url_h2] => {
[0]=>"textnode",
etc...
},
[url_h3] => {
[0]=>"textnode",
etc...
},
[url_h4] => {
[0]=>"textnode",
etc...
},
[url_h5] => {
[0]=>"textnode",
etc...
},
[url_h6] => {
[0]=>"textnode",
etc...
},
[url_links] => {
[textnode]=>"href attribute",
etc.....
},
[url_img] => { [0]=>{
[src]=>"",
[alt]=>""
},
etc.....
}
}
In the example above we use the element 's ID "manage" as the parseUrl method first parameter.This is useful only
to print a brute format of the object data in the chosen element.To avoid this behavior you can fill an empty
string or an inexistent ID.
You can also use this object "e.detail.document" to handle the parsed URL DOM tree directly in your code
or in the short way if your response variable is "response" for example : response.document.
example: alert(response.document.getElementsByTagName('title')[0].innerText);
//or
alert(e.detail.document.getElementsByTagName('title')[0].innerText); |