Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i get stats of a web site with vb 2

Status
Not open for further replies.

Nuqe

Technical User
May 6, 2003
57
CA
I'm writing a program to calculate points for a nhl draft. I wanted to know if it is possible to take the stats off the page into an array, or at least put the text/code into a string wich i can sort through later. If it can't be done, then it almost seems useless to have a program if all stats have to be looked up.
any help would be great thanks

Nuqe
 

Use advanced search and search for webbrowser. You should find (with enough looking) all the code you need.

Good Luck

 
Thanks... i did some searching as you said, and did find information of that nature. I'm a beginner at this so i might have to ask some more questions as I try and figure this out.
thanks a bunch vb5prgrmr
 
Nhl points, from someone elses web site? Naughty Naughty..just kidding. You need to consider that they may change their page, however assuming that it is stored in an html table or whatever you can use the Browsers DOM to parse the data.
 
:) I stole them points good lol. the information i need is indeed stored in tables. i'm very unfamiliar with this webbrowser control. dom?? what do you mean by parse the data. don't laugh hehe, my vb teacher made us do boring stuff. thanks

Nuqe
 
hey vb5prgrmr i tried some of the code from a few sources and get one error every time i try.
this is the error "object doesn't support this property or method" and always happens on this line of code help.. =S

myHTMLDoc = DocumentFactory.createDocumentFromUrl(strURL, "")
 

That must be from thread222-514080 where strongm says you will need a reference to the Microsoft HTML OBject library. GoTo Project>References.

Good Luck

 
Hmmm i've already done that... any other ideas?

Nuqe
 
I'm running w2k pro and have IE 5 with sp2 on it

Nuqe
 

hmmm....

did you cut and paste strongm's example? Did you remove the ";" from the string that is right after your strURL?

I just did a cut-n-paste of his code after adding the reference to a new project and it worked like a champ.

Take a close look at your syntax and references.

Good Luck

 
I did a copy paste, of that code, and got the same error, i dunno, i'm going to try it on my system at home i guess.. i'm thinking it might be the vb version that i'm using, its some learning edition, maybe there are limitations, i dunno. thanks for your help. i'll do it tonight if i get a chance and let you know

Nuqe

I was going to read the VB book for dummies, but the covers where too far apart... :)
 
Hey vb5prgrmr just wanted to say i got that code working... it doesn't do exactly what i want yet, but i'm working on it. i just want to ask a amateur question. I noticed that a "function" was used in that code, and wondered what the circumstances are for using one instead of using a sub and calling it..


nuqe

I was going to read the VB book for dummies, but the covers where too far apart... :)
 
Normally you use a function to return a value. In this case I would think it would be a string, the contents of the web page.
[tt]
Private Sub Command1_Click()
MsgBox GetMyString
End Sub

Private Function GetMyString() As String
GetMyString = "This is a test"
End Function
[/tt]

There are other ways to return value from subs and functions and that is by declaring a variable byref in the arguements of the sub or function...
[tt]
Option Explicit

Private Sub Form_Load()
Dim S As String
MyTest S
MsgBox S
End Sub

Private Sub MyTest(ByRef MyString As String)
MyString = "This is a test"
End Sub
[/tt]

or lets say you wanted to add some other logic to the function that gets the web page and you wanted to know if it was successful or not. You could then return a boolean value and a byref string with the contents....
[tt]
Option Explicit

Private Sub Command1_Click()
Dim MyString As String
If GetWebPage(" MyString) = True Then
'Dowork
End If
End Sub

Private Function GetWebPage(URL As String, ByVal strResult As String) As Boolean
Dim DocumentFactory As HTMLDocument
Dim myHTMLDoc As HTMLDocument
Set DocumentFactory = New HTMLDocument
Set myHTMLDoc = DocumentFactory.createDocumentFromUrl(URL, "")
Do Until myHTMLDoc.readyState = "complete"
DoEvents
Loop
strResult = myHTMLDoc.documentElement.outerHTML

If Len(strResult) <= 41 Then
GetWebPage = False
Else
GetWebPage = True
End If
End Function

[/tt]

I hope this helps, Good Luck
 
hey thanks, the code i had copied from here, worked... but only when i was opening it with visual studio and not this crappy learning edition. just figured i'd mention that. it could also be some other problem somewhere, but that's what i've drawn out of it.

Nuqe

I was going to read the VB book for dummies, but the covers where too far apart... :)
 
functions etc. make more sense now, thanks... just another question.. this code here

If Len(strResult) <= 41 Then
GetWebPage = False
Else
GetWebPage = True
End If
End Function

just wondering if 41 has any significance or if it's just a bum number you added.

I was going to read the VB book for dummies, but the covers where too far apart... :)
 

An unknown website or webpage will return...
[tt]
<HTML><HEAD></HEAD>
<BODY></BODY></HTML>
[/tt]
of which is 41 characters long. If you use my example above and place a break on the if len line and do a debug.print strResult you will see what I am talking about.

Good Luck

 
woo woo thanks for helping. this is the most help i've ever gotten from somebody. I'm just finishing college... so if i ever make a wack load of cash, i'll send some your way hahaha cheers

Nuqe

I was going to read the VB book for dummies, but the covers where too far apart... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top