Solved

Retrieving HTML source from a URL

Posted on 2002-07-17
8
141 Views
Last Modified: 2010-05-02
I've tried the INet control, the WebBrowser control, and the MSHTML library without success.  I simply want to pass in a URL to something and get back the entire HTML source which I can then parse through for my own purposes.  Surely there must be an easy way to do this!
0
Comment
Question by:rmayer
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
Use

WebBrowser1.Document.Body.InnerHTML

This should return the HTML source for the URL when the document_complete event is fired.
0
 

Author Comment

by:rmayer
Comment Utility
But, what method do I use to cause DocumentComplete to fire?  I assume you are using Navigate, but it only works if I make the WebBrowser control Visible.  I don't want it to be visible because I'm only interested in capturing the HTML source.  Any ideas?
0
 
LVL 4

Expert Comment

by:RichW
Comment Utility
If you're asking how to make sure the readystate is complete:

Do While WebBrowser1.ReadyState < 4 '= READYSTATE_COMPLETE
    DoEvents
Loop

RichW
0
 

Author Comment

by:rmayer
Comment Utility
But, what method do I use to cause DocumentComplete to fire?  I assume you are using Navigate, but it only works if I make the WebBrowser control Visible.  I don't want it to be visible because I'm only interested in capturing the HTML source.  Any ideas?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 33 total points
Comment Utility
Inet control:

dim sContents as string

sContents=inet1.openurl("http://wwww.domain.com/index.html",icString)



Webbrowser controlary:
As tim close suggested:
on Webbrowser Document_complete event:

if (pdisp is webbrowser1.object) then
   sContents=webbrowser1.document.documentelement.innerhtml
end if

I use documentelement since it returns all the contents (title,head, script and so on) while body only returns Body contents.

Hope it helps
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Make a reference to MSXML (v2.6, v3 or v4)
Try this code (it seems to work for me):

Private Sub cmdOK_Click()
Dim httpObj As MSXML2.XMLHTTP

Set httpObj = New MSXML2.XMLHTTP
With httpObj
  .open "GET", "http://www.msn.com", False
  .send
  txtOutput.Text = .responseText
End With
Set httpObj = Nothing

End Sub

Note:  If you are using a prior version to v2.6, than change the code as follows:
Dim httpObj As MSXML.XMLHTTPRequest

Set httpObj = New MSXML.XMLHTTPRequest

Anthony
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi rmayer,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: TimCottee and Richie_Simonetti and acperkins@devx
    *** hehehe

rmayer, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange

TimCottee points added to unclaimed points (almost 500) for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20463697.html

acperkins points added to unclaimed points for you at:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20471358.html
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now