开发者

programmatically figure out the height and width at which an html will render in the browser with C#

I have almost 200,000 html pages and I need to figure out the height and width at which each html will render in开发者_JAVA百科 any browser. I only need approximate numbers. How I can programmatically do this with C#?


C# Does not execute inside of a browser, and should not be used to try and determine the width and height a given HTML page will render at in a browser. Moreover, there is no answer for "any browser", as different browsers may support different fonts, may render the same content slightly different, and may be configured with different display-related settings (most browsers allow the user to arbitrarily scale the default font size up or down as desired, which would of course impact the final render size).

In general, however, I would suggest you do something like:

  1. Come up with a JavaScript snippet that can compute the current size of the document.
  2. Write a C# (or Java, C, bash, etc.) program to append your snippet to each of your 200,000 pages.
  3. Use a browser-based test-harness like Selenium or Webdriver to load up each of your 200,000 pages, extract the result from your JavaScript snippet, and log it out to somewhere convenient.
  4. Optionally, you can repeat step 3 with different browsers to get the width/height for all the different browsers that you care about.

Edit: Apparently Webdriver and Selenium are the same thing now. When did that happen?


It's pretty straightforward. Just write an HTML parser and enough of a rendering engine to at least know the height and width of any HTML element (for any screen size, font setting?). Obviously you will need a CSS parser and engine. Since you want to know for any browser, you will need to have modes of emulating each. If you can't directly get the DOM of the HTML pages you are trying to measure you will need a java-script engine to get the values as they appear on the page.

Or you could run the HTML in a browser and use java-script to get the values. This won't be in .NET, though. You could have the java-script post the data to an ASP.NET page if you like though.

Or you could use one of the tools recommended in answer to your earlier question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜