0

i'm trying to get some attributes for HTML tags in web page for example

<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 with #musicNav in my PHP program , since php is server side i can't get these attribute so i'm thinking to append javascript code to calculate these attribute and store 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 by php file contain my algorithm witch extract visual features from webpages.

but my problem is i need to render the webpage with appended javascript using some browser or rendering engine in PHP or java ... so dose any one have some thing like that? is my method right or there is better solution?

4
  • I don't think, this approach is a good idea at all - as you never know which height the browser renders for your element, especially if it's a dynamic value. If it's a fixed value (e.g. height: 400px), maybe it's better to set this as PHP variable and put it into your html as inline style. Commented Jun 28, 2012 at 14:26
  • @ maksimov i didn't understand what u mean @ acme this is not a problem because i don't need the dimensions of the elements to be fixed for all screen sizes i just need to get a ratio between the elements size rendered on fix resolution e.g "1366X766" Commented Jun 28, 2012 at 14:45
  • @FarokOjil I came here because this question is tagged as [java] and has "Java" in the title. However it appears to have nothing to do with Java at all, but PHP and JavaScript. Otherwise, you need to explain what you mean when you refer to Java together with PHP. Commented Jun 28, 2012 at 14:55
  • i mean by java " rendering engine written in java " Commented Jun 28, 2012 at 17:05

2 Answers 2

1

Incase you want to render a webpage given a url and need an api to walk through the rendered dom Phantomjs and its api and examples will help you. Check out open render

PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

Sign up to request clarification or add additional context in comments.

Comments

0

If i understand you correctly, you need a means to control the browser from your java app. This seems to be relevant. Things you may also want to account for --

  1. Letting the app know about your browser(binary or otherwise).
  2. Choosing from multiple available browsers on the host.
  3. Account for cross-platform support.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.