I am trying to get some attributes for HTML tags in a web page, like
<html> <head> <title>test page</title> </head> <body> <div id="header" class="clearit" role="banner"> <div id="headerWrapper"> <ul id="primaryNav" role="navigation"> <li id="musicNav" class="navItem"> <a href="/music" class="nav-link">Music</a> </li> <li id="listenNav" class="navItem"> <a href="/listen" class="nav-link">Radio</a> </li> <li id="eventsNav" class="navItem"> <a href="/events" class="nav-link">Events</a> </li> <li id="chartsNav" class="navItem"> <a href="/charts" class="nav-link">Charts</a> </li> <li id="communityNav" class="navItem"> <a href="/community" class="nav-link">Community</a> </li> <li id="originalsNav" class="navItem"> <a href="http://originals.last.fm" class="nav-link">Originals</a> </li> </ul> </div> </div> </body> </html>
For example, I need the actual height and width for #headerWrapper and compare it to C # musicNav in my PHP program, since php is the server side, I cannot get this attribute, so I am thinking of adding javascript code to calculate these attribute and save it in json file like this code
<script type="text/javascript"> document.ready(function() { var JSONObject= { "tagname":"headerWrapper", "height":$("#headerWrapper").height(), "width":$("#headerWrapper").width() }, { "tagname":"musicNav", "height":$("#musicNav").height(), "width":$("#musicNav").width() } }); }); </script>
then read it in a php file containing my algorithm that extracts visual functions from web pages.
but my problem is that I need to display a web page with javascript added using some browser or rendering engine in PHP or java ... so does anyone have a dose like that? Is my method correct or is there a better solution?
source share