|
-
Apr 4th, 2001, 08:02 PM
#1
Thread Starter
PowerPoster
o.k i know i posted this yesterday! And this is mainly for geoff_xrx or bloodeye or anyone else who reckons they got an answer!
The code below is suposed to search a particular web sites and find the words a specify in the code.
But when run it, it goes to the site fine and lists the url name countless times until i get an error. The thing is it does this even when there are no matching results! why?
I'm using the web browser control!
Option Compare Text
Dim site(2) As String
Dim words(2) As String 'just a few words....you'll have to add them all
Dim siteNum As Integer
Private Sub Form_Load()
Web1.Navigate "http://www.riu.com.au"
site(0) = "http://www.riu.com.au"
words(0) = "Resource Service Group"
siteNum = 0
End Sub
Private Sub nextSite()
Web1.Navigate site(siteNum)
Do Until Web1.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
siteNum = siteNum + 1
End Sub
Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim itext As String
Dim x As Integer
Me.Caption = "site:" & siteNum & " " & URL
If (pDisp Is Web1.object) Then
itext = Web1.Document.documentElement.innerText
For x = 0 To UBound(words)
If InStr(itext, words(x)) < 0 Then
List1.AddItem Web1.LocationURL
nextSite
Exit Sub
End If
Next x
nextSite
End If
End Sub
-
Apr 4th, 2001, 08:18 PM
#2
Hyperactive Member
Try the following code
Code:
Option Compare Text
Dim site(2) As String
Dim words(2) As String 'just a few words....you'll have to add them all
Dim siteNum As Integer
Private Sub Form_Load()
Web1.Navigate "http://www.riu.com.au"
site(0) = "http://www.riu.com.au"
words(0) = "Resource Service Group"
siteNum = 0
End Sub
Private Sub nextSite()
Web1.Navigate site(siteNum)
End Sub
Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim itext As String
Dim x As Integer
Me.Caption = "site:" & siteNum & " " & URL
If (pDisp = Web1.object) Then
itext = Web1.Document.documentElement.innerText
For x = 0 To UBound(words)
If InStr(itext, words(x)) < 0 Then
List1.AddItem Web1.LocationURL
nextSite
Exit Sub
End If
Next x
siteNum = siteNum + 1
nextSite
End If
End Sub
The first mistake was that the comparison
(pDisp Is Web1.object)
should be
(pDisp = Web1.object)
The thing that was really screwing you up was the doevents in the loop. This was constantly forcing the web page to refresh. I've got rid of it now, so once you tell it fetch the page no more code will be queued up for execution until the DocumentComplete event is triggered.
I've moved the increment for siteNum out into te DocumentComplete code as well.
Of course now it runs off the end of the array, but I'm sure you can sort that out 
I hope this is of some help,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 08:24 PM
#3
Thread Starter
PowerPoster
this maybe stupid! sorry if it is!
cheers but i get the error "subscript out of range" then highlights Web1.Navigate site(siteNum) why?
I had got it to stop searching and refreshing by adding another if statement in but when it did find soemthing it would still keep refreshing and listing!
-
Apr 4th, 2001, 08:32 PM
#4
Hyperactive Member
You have defined the array site to have an upper limit of 2.
You add 1 to SiteNum each time you load a new web page.
So first time round it equals 0. Fine, it loads the site
Second and third time round it equals 1 and two respectively. Still no problem, but because there isn't anything in the site array for these values, it will not display any web pages.
Fourth time around, the value of SiteNum is 3. As soon as you try to access that array element the system stops. Remember you only defined the arrayy Site to have 3 elements i.e. 0,1 and 2.
You can cheque to see if it's done all the array elements with the following code
Code:
Private Sub nextSite()
If siteNum > UBound(site) Then
End
End If
Web1.Navigate site(siteNum)
End Sub
Cheers,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 08:55 PM
#5
Thread Starter
PowerPoster
Hassling! Sorry
Now it just ends. B4 it gets the chance to search.
I made words(0) = "Salamar" which is on the riu site. It should return the url in the list box but it closes b4 it gets the chance!
Any ideas?
I tried exit sub instead of end but that doesn't work either!
-
Apr 4th, 2001, 09:24 PM
#6
Thread Starter
PowerPoster
Could I do it this way?
SD!
Can i do it this way? Without using sitenum. Just enter it in!
Option Compare Text
Dim site(2) As String
Dim words(2) As String 'just a few words....you'll have to add them all
Dim siteNum As Integer
Private Sub Form_Load()
Web1.Navigate "http://www.riu.com.au/gold/secure"
site(0) = "http://www.riu.com.au/gold/secure"
site(1) = "www.yahoo.com"
words(0) = "Global"
siteNum = 0
End Sub
Private Sub nextSite()
Web1.Navigate site(1)
End Sub
Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim itext As String
Dim x As Integer
Me.Caption = "site:" & siteNum & " " & URL
If (pDisp Is Web1.object) Then
itext = Web1.Document.documentElement.innerText
For x = 0 To UBound(words)
If InStr(itext, words(x)) <> 0 Then
List1.AddItem Web1.LocationURL
nextSite
Exit Sub
ElseIf InStr(itext, words(x)) = 0 Then
MsgBox "no records"
Exit Sub
End If
Next x
nextSite
End If
End Sub
-
Apr 4th, 2001, 09:47 PM
#7
Hyperactive Member
Calling the nextsite will always send you to the same site www.yahoo.com
Give me a few minutes to have a look at the previous code and I'll get back to you.
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 09:57 PM
#8
Hyperactive Member
Okay to stop the program ending straight away change the "End" to "Exit Sub" in nextsite
Code:
Private Sub nextSite()
If siteNum > UBound(site) Then
Exit Sub
End If
Web1.Navigate site(siteNum)
End Sub
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 10:08 PM
#9
Thread Starter
PowerPoster
ta!
But it doesn't return any results! It just exits!
When there are results.
Any clue.
Thanks heaps for your help this has had me bugged for days!
-
Apr 4th, 2001, 10:12 PM
#10
Hyperactive Member
okay, here's the new code
Code:
Option Compare Text
Dim site(2) As String
Dim words(0) As String 'just a few words....you'll have to add them all
Dim siteNum As Integer
Private Sub Form_Load()
Web1.Navigate "http://www.riu.com.au"
site(0) = "http://www.riu.com.au"
words(0) = "Salamar"
siteNum = 0
End Sub
Private Sub nextSite()
If siteNum > UBound(site) Then
Exit Sub
End If
Web1.Navigate site(siteNum)
End Sub
Private Sub web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim itext As String
Dim x As Integer
Me.Caption = "site:" & siteNum & " " & URL
If (pDisp = Web1.object) Then
itext = Web1.Document.documentElement.innerhtml
For x = 0 To UBound(words)
If InStr(1, itext, words(x)) <> 0 Then
List1.AddItem Web1.LocationURL
Exit For
End If
Next x
siteNum = siteNum + 1
nextSite
End If
End Sub
I've changed a few things.
First, I've redimensioned words to 1 element. This because if you do not populate the rest of the words in the array, then they will be empty. And when you go searching websites you will always find the empty string so you would get every website back.
The line
itext = Web1.Document.documentElement.innerhtml
looks at the html, I think before you were just looking at the header.
You missed a > sign in the following line
If InStr(1, itext, words(x)) <> 0 Then
I would never have returned true otherwise.
I also changed the next couple of lines to stop it constantly calling next site without properly re-starting the routine.
And it still doesn't work. Why? Because the page word you are looking for is held in an html frame which is not part of innerhtml.
If you change the search word from Salamar to information or search non framed pages it will work.
P.S. it throws up the first page twice because of the following lines
Web1.Navigate "http://www.riu.com.au"
site(0) = "http://www.riu.com.au"
try something like
Web1.Navigate "http://www.riu.com.au"
site(0) = "http://www.nextpage.com"
So the only question is how do you look inside frames. Sorry I don't know off hand. I've got to go and eat my supper now. So I hope this helps,
I'll look at this thread again tommorrow.
Cheers,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Apr 4th, 2001, 10:31 PM
#11
Thread Starter
PowerPoster
thanks again!
I'll try the frames thingy. Maybe a few other guy's can get that bit!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|