Rendering HTML pages in PHP or Java

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?

0
source share
2 answers

If you understand correctly, you need a tool to control the browser from your java application. This seems relevant. Things you can also consider -

  • Providing knowledge of the application about your browser (binary or otherwise).
  • Choose from several available browsers on the host.
  • Cross-platform support.
0
source

If you want to display a webpage with a URL and you need an api to go through the provided Phantomjs house and api and examples will help you. Check open render

PhantomJS is a mute WebKit with a JavaScript API. It has fast and fast built-in support for various web standards: DOM processing, CSS selector, JSON, Canvas and SVG.

0
source

All Articles