How to get the visible text in ie with vba?

2019-09-07 12:45发布

问题:

I'm trying to scrape some text from a webpage using excel. The page has a lot of js with decision trees, so when I use ie.document.body.innertext, I will see those if statements. I do not want to deal with those. I want the result that they output onto the screen. outertext doesn't work either because it appears to give the same result as innertext. Innerhtml & outerhtml also show the decision trees.

Any ideas on how to get the visible text that's painted on the screen?

回答1:

I would suggest using the Selenium Webdriver, which extends the ability to do browser-based automation.

HERE is a good overview.

HERE is the download/documentation.

Here is an example of its use:

Sub GetWebPageText(url$)
' REQUIRES REFERENCE TO THE SELENIUM WEBDRIVER TYPE LIBRARY
Dim selenium As New SeleniumWrapper.WebDriver

selenium.Start "InternetExplorer", url

selenium.Open url

Debug.Print selenium.getBodyText



End Sub