Parsing HTML returned in WinHttpRequest.ResponseText

I've successfully used the Microsoft WinHTTP Services library to log in to a website and then GET a particular page I'm interested in, however the returned ResponseText is just a massive string.  I can obviously write code to parse this text, but I have a feeling that the Microsoft HTML Object Library might be able to do a lot of the leg work for me.

I've had a go loading the HTMLDocument (see below), but I'm not sufficently familiar with the DOM object model to know if this is the right approach - or more importantly how to extract the anchors I want from the returned page.

Any ideas?
Dim htpRequest As WinHttp.WinHttpRequest
Dim docDocument As MSHTML.HTMLDocument

htpRequest.Open "GET", "", False
docDocument.body.innerHTML = htpRequest.responseText

Open in new window

LVL 17
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This sample database will show you how to transfer information to and from the internet using the Web Browser control, Internet Explorer Automation and FTP -

You can use the InnerText property from the Microsoft HTML Object Library to extract the text from the HTML.
Jez, I know of no way to look for anything in particular, other than using string manipulation functions, like InStr and Mid.

HTML is not fully structured, so there's no sort of object references where you can say "get text of a cell X"

If you were looking for something in particular, you would have to figure out some unique text around it (a cell label maybe), and get the text in the next cell afterwards.

Here's an example of ResponseText parsing:


JezWaltersAuthor Commented:
It's been quite a learning curve but I've managed to extract the anchors I'm after using the Microsoft WinHTTP Services library to get pages and the Microsoft HTML Object library to parse them.  In case anyone else is interested, the code in my question was spot on (apart from the missing New keywords).
Having got my page, I had to recursively loop through the elements in HTMLDocument.body.all, looking for an IHTMLElement with a TypeName of "HTMLAnchorElement".
Once located, the href is just a property of the HTMLAnchorElement object - bingo!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fair enough. That's good to know.  I might use that in future....looks handy.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.