|
-
Aug 21st, 2001, 12:50 AM
#1
Thread Starter
PowerPoster
Good One For Web People
hey all,
What i'm trying to do is the following:
I have some code that searches the webbrowser control's current page for links!
Now what i need it to do is:
1) Navigate to a page search for links. then
2) Navigate to next page search for links then continue this for all 6 sites!
Now when it searches for links it calls a sub. I need to call it each time.
Anyone have an idea.
I know i need a loop somewhere but how!
thanks
b
-
Aug 21st, 2001, 01:16 AM
#2
Frenzied Member
Here's some code to play with.
The 2 subs will list all the href of the Links, or the outerText of the Links.
Make a Reference to the MSHTML.lib(Microsoft HTML Object Library).
Form Code:
VB Code:
Dim doc As HTMLDocument
Private Sub Form_Load()
WebBrowser1.Navigate "http://www.hairdos.com/frameset.htm"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set doc = Nothing
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, _
URL As Variant, Flags As Variant, TargetFrameName As Variant, _
PostData As Variant, Headers As Variant, Cancel As Boolean)
Set doc = Nothing
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = WebBrowser1.Document
If (pDisp Is WebBrowser1.Object) Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
End If
End Sub
Public Sub ListAllLinkUrls(doc As HTMLDocument, List As ListBox)
Dim i As Long
Dim x As Long
If doc.frames.length = 0 Then
For i = 0 To doc.links.length - 1
List.AddItem doc.links(i).href
Next i
Else
For i = 0 To doc.frames.length - 1
For x = 0 To doc.frames(i).Document.links.length - 1
List.AddItem doc.frames(i).Document.links(x).href
Next x
Next i
End If
End Sub
Public Sub ListAllLinks(doc As HTMLDocument, List As ListBox)
Dim i As Long
Dim x As Long
If doc.frames.length = 0 Then
For i = 0 To doc.links.length - 1
If doc.links(i).outerText <> "" Then
List.AddItem doc.links(i).outerText
End If
Next i
Else
For i = 0 To doc.frames.length - 1
For x = 0 To doc.frames(i).Document.links.length - 1
If doc.frames(i).Document.links(x).outerText <> "" Then
List.AddItem doc.frames(i).Document.links(x).outerText
End If
Next x
Next i
End If
End Sub
To have it navigate from web-page to web-page try this.
VB Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set doc = WebBrowser1.Document
If (pDisp Is WebBrowser1.Object) Then
If URL = "http://www.first-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.second-page.com"
Elseif URL = "http://www.second-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.third-page.com"
Elseif URL = "http://www.third-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.fourth-page.com"
End If
End If
End Sub
-
Aug 21st, 2001, 01:22 AM
#3
Hyperactive Member
Try
Code:
Dim objCol as object
Dim objEl as object
' webb.document.Anchors gets only anchors with Name or ID
' according to the doc.
Set objCol = webb.Document.GetElementsByTagName("A")
For Each objEl in objCol
.....
Next
after that, go for DHTML on www.MSDN.microsoft.com under Web Development
-
Aug 21st, 2001, 01:54 AM
#4
Thread Starter
PowerPoster
cheers!
Bloodeye:
I get the error ByRef type mismatch and it highlights this
ListAllLinks doc, list1 in particular the list1 bit!
Any ideas
-
Aug 21st, 2001, 02:08 AM
#5
Hyperactive Member
Did you put List1 on your form as listbox?
-
Aug 21st, 2001, 02:19 AM
#6
Thread Starter
PowerPoster
oh der oh derr!
I called my list box links thanks John!
But it didnt change pages nor did it put anything in the list box?
I'm probably bieng stupid again. Seems i'm having one of those days!
-
Aug 21st, 2001, 10:00 AM
#7
Hyperactive Member
Try
Code:
Select Case Lcase(URL)
Case URL = "http://www.first-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.second-page.com"
Case "http://www.second-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.third-page.com"
Case "http://www.third-page.com" Then
ListAllLinks doc, List1
'ListAllLinkUrls doc, List1
WebBrowser1.Navigate "http://www.fourth-page.com"
End Select
I'm not entirely sur what yoa are doing. To visit a link, I find it by hook or crook with webb.Document.GetElementsByTagName .GetelementByName etc then
Set objEle = found
objele.Click.
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
|