Retrieving HTML source from a URL

Posted on 2002-07-17
Medium Priority
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!
Question by:rmayer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 43

Expert Comment

ID: 7159849


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

Author Comment

ID: 7159973
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?

Expert Comment

ID: 7159990
If you're asking how to make sure the readystate is complete:

Do While WebBrowser1.ReadyState < 4 '= READYSTATE_COMPLETE

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 7160265
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?
LVL 16

Accepted Solution

Richie_Simonetti earned 132 total points
ID: 7160292
Inet control:

dim sContents as string


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

if (pdisp is webbrowser1.object) then
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
LVL 75

Expert Comment

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

Private Sub cmdOK_Click()

Set httpObj = New MSXML2.XMLHTTP
With httpObj
  .open "GET", "http://www.msn.com", False
  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

LVL 49

Expert Comment

ID: 8013844
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

Expert Comment

ID: 8096085
per recommendation

Community Support Moderator @Experts Exchange

TimCottee points added to unclaimed points (almost 500) for you at:

acperkins points added to unclaimed points for you at:

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 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