Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Visual Basic (VB 4/5/6) » Internet/Communications Programming » Getting Webpage HTML as String

26 posts, Page 1 of 3. 123»»»

Getting Webpage HTML as StringExpand / Collapse
Author
Message
Posted 1/25/2006 11:58:39 AM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 1/20/2008 1:18:14 AM
Posts: 545, Visits: 1,021
moved from General forum
http://www.a1vbcode.com/vbforums/Topic16179-3-1.aspx

you shouldn't've gotten an error on that cuz it works fine for me in vb6.

if this is correct it says I need to define a varible but the one i defined is not right i put Dim stext1() As String

what are you talking about with stext()?

also... instead of:

GetPageHTML = objDoc.documentElement.outerHTML

use this...

GetPageHTML = objDoc.body.innerHTML

you don't need to return the whole webpage.. just get what's in the body tag.

Post #16194
Posted 1/25/2006 6:51:29 PM


Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2/9/2006 11:02:34 AM
Posts: 16, Visits: 45
Im getting a "compile error" Varible not defined. here is the code . the copile error is coming up at the end of the code which is underlined at the bottom. the program has a command button and a list box only. would that be all i needed?

Option Explicit

Private Function GetPageHTML(ByVal strUrl As String) As String
Dim objMSHTML As MSHTML.HTMLDocument
Dim objDoc As MSHTML.HTMLDocument

Set objMSHTML = New MSHTML.HTMLDocument
Set objDoc = objMSHTML.createDocumentFromUrl(strUrl, vbNullString)

Do
DoEvents
Loop Until objDoc.readyState = "complete"

DoEvents

GetPageHTML = objDoc.body.innerHTML

Set objDoc = Nothing
Set objMSHTML = Nothing
End Function

Private Sub Command1_Click()
Text1.Text = GetPageHTML("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")
End Sub
Post #16211
Posted 1/25/2006 7:25:24 PM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 1/20/2008 1:18:14 AM
Posts: 545, Visits: 1,021
the program has a command button and a list box only.

Text1.Text

what is Text1???  you said that your form only has a button and a listbox.  it looks like you're trying to put the html code in a textbox.. because Text is a textbox property.. but if you don't have a textbox then how are you supposed to pull this off?  either that or Text1 is a user-defined class module and you didn't declare it with the New keyword.  you're getting that error because vb doesn't know what Text1 is, either.

msgbox it.  it works.

Post #16212
Posted 1/25/2006 7:48:49 PM


Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2/9/2006 11:02:34 AM
Posts: 16, Visits: 45
That makes sense with the text.. i deleted that part out of the code but im getting a different message now here where im at the underline is where im getting the eroor message "compile error user defined type not defined"
I really appreciate your patience.


Option Explicit

Private Function GetPageHTML(ByVal strUrl As String) As String
Dim objMSHTML As MSHTML.HTMLDocument
Dim objDoc As MSHTML.HTMLDocument

Set objMSHTML = New MSHTML.HTMLDocument
Set objDoc = objMSHTML.createDocumentFromUrl(strUrl, vbNullString)

Do
DoEvents
Loop Until objDoc.readyState = "complete"

DoEvents

GetPageHTML = objDoc.body.innerHTML

Set objDoc = Nothing
Set objMSHTML = Nothing
End Function

Private Sub Command1_Click()
GetPageHTML ("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")
End Sub
Post #16214
Posted 1/25/2006 8:39:17 PM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 1/20/2008 1:18:14 AM
Posts: 545, Visits: 1,021
LLLOOLOLOL.. i thought that code looked familiar.  no wonder none of your code is working.  that's mark's code from http://www.a1vbcode.com/a1vbcode/vbforums/Topic15194-3-1.aspx when he was helping me when i knew nothing about this... and you copied and pasted it lloool.

you need to add microsoft html object library (mshtml.tlb) to your project.  that's why you're getting that error.  vb doesn't see the mshtml data type anywhere and so it's looking for a user-defined type/class that doesn't exist.

also add microsoft internet controls (shdocvw.dll), as well.. you might need it later if you get further in-depth in this area.

Post #16216
Posted 1/25/2006 9:31:38 PM


Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2/9/2006 11:02:34 AM
Posts: 16, Visits: 45
ok, here is what I did I added the two contols microsoft html object library (mshtml.tlb)and microsoft internet controls (shdocvw.dll) I dragged a box up on the program which was the mshtml.tlb and ran it and i still got the error message . I'm guessing the mshtml.tlb will be the box that the data is displayed in so i deleted the list box because i wont need that correct. i'm not sure what's going on. maybe something is going on in the properties.
Post #16220
Posted 1/25/2006 11:19:05 PM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 1/20/2008 1:18:14 AM
Posts: 545, Visits: 1,021
you're still getting the error cuz you added the webbrowser control.  you need to add the reference so you can use the code in the library.  the control is for forms.. and allows you to sorta make your own, custom browser.

also..

Private Sub Command1_Click()
 ?  GetPageHTML ("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")
End Sub

better fix that.. either msgbox it, debug.print it, or store it in a variable.

Post #16228
Posted 1/25/2006 11:57:27 PM


Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2/9/2006 11:02:34 AM
Posts: 16, Visits: 45
ok but how do I add it as a reference .

Post #16233
Posted 1/25/2006 11:58:15 PM


Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 2/9/2006 11:02:34 AM
Posts: 16, Visits: 45
I'm not sure i follow you on the message box thing. would i just put the msg before the begining of the
GetPageHTML ("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")

sorta like this .......MsgBox GetPageHTML ("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")
Post #16234
Posted 1/26/2006 7:42:25 AM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 1/20/2008 1:18:14 AM
Posts: 545, Visits: 1,021
ok but how do I add it as a reference

you wrote a database program??  look at the top of your vb window.  i can't think of the exact name, but it should be in a menu section up there and it should be named references.  look it up in help if you're not sure.

MsgBox GetPageHTML ("http://198.184.209.151:81/caspsamp/mcso/jp_dr.asp")

yeah, just like that.

Post #16243