问题
I'm using Java with the Selenium Library to scrape a webpage. When I use Firebug on the page in Firefox, I can see that the page's source contains the following HTML structure:
<div>
<div>
<table>
<caption />
<thead />
<tbody />
</table>
</div>
</div>
However, when I programatically download the page's source using HtmlUnitDriver, then use driver.getPageSource(), I see that the corresponding HTML structure has changed to:
<div>
<table>
<caption />
<tbody />
</table>
</div>
- Why does the HtmlUnitDriver's report differ to that given by Firebug?
- Can I set up firebug so that I can inspect the HTML structure according to how the HtmlUnitDriver will report it?
回答1:
Note that Firebug does not adjust the HTML structure that way, i.e. the integrated developer tools should show you the same.
I assume the second wrapping <div>
and the <thead>
get added by some JavaScript running on the page.
You can check that by disabling JavaScript, e.g. by going to about:config and setting javascript.enabled
to false
or via an add-on like NoScript or Ghostery.
来源:https://stackoverflow.com/questions/39190327/how-can-i-get-firebug-to-match-htmlunitdrivers-pagesource-report