[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4099
  • Last Modified:

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", "http://www.mywebsite.com/mypage.asp", False
htpRequest.send
docDocument.body.innerHTML = htpRequest.responseText

Open in new window

1
JezWalters
Asked:
JezWalters
  • 2
1 Solution
 
thenelsonCommented:
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 - www.thenelson.name/#WebAccess

You can use the InnerText property from the Microsoft HTML Object Library to extract the text from the HTML.
0
 
RobSampsonCommented:
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:
http://www.experts-exchange.com/Programming/Languages/Q_23096722.html

Regards,

Rob.
0
 
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!
0
 
RobSampsonCommented:
Fair enough. That's good to know.  I might use that in future....looks handy.

Rob.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now