Results 1 to 7 of 7

Thread: Good One For Web People

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    Exclamation 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

  2. #2
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    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:
    1. Dim doc As HTMLDocument
    2.  
    3. Private Sub Form_Load()
    4.     WebBrowser1.Navigate "http://www.hairdos.com/frameset.htm"
    5. End Sub
    6.  
    7. Private Sub Form_Unload(Cancel As Integer)
    8.     Set doc = Nothing
    9. End Sub
    10.  
    11. Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, _
    12. URL As Variant, Flags As Variant, TargetFrameName As Variant, _
    13. PostData As Variant, Headers As Variant, Cancel As Boolean)
    14.     Set doc = Nothing
    15. End Sub
    16.  
    17. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    18.     Set doc = WebBrowser1.Document
    19.     If (pDisp Is WebBrowser1.Object) Then
    20.         ListAllLinks doc, List1
    21.         'ListAllLinkUrls doc, List1
    22.     End If
    23. End Sub
    24.  
    25.  
    26. Public Sub ListAllLinkUrls(doc As HTMLDocument, List As ListBox)
    27.     Dim i As Long
    28.     Dim x As Long
    29.    
    30.     If doc.frames.length = 0 Then
    31.         For i = 0 To doc.links.length - 1
    32.             List.AddItem doc.links(i).href
    33.         Next i
    34.     Else
    35.         For i = 0 To doc.frames.length - 1
    36.             For x = 0 To doc.frames(i).Document.links.length - 1
    37.                 List.AddItem doc.frames(i).Document.links(x).href
    38.             Next x
    39.         Next i
    40.     End If
    41. End Sub
    42.  
    43. Public Sub ListAllLinks(doc As HTMLDocument, List As ListBox)
    44.     Dim i As Long
    45.     Dim x As Long
    46.    
    47.     If doc.frames.length = 0 Then
    48.         For i = 0 To doc.links.length - 1
    49.             If doc.links(i).outerText <> "" Then
    50.                 List.AddItem doc.links(i).outerText
    51.             End If
    52.         Next i
    53.     Else
    54.         For i = 0 To doc.frames.length - 1
    55.             For x = 0 To doc.frames(i).Document.links.length - 1
    56.                 If doc.frames(i).Document.links(x).outerText <> "" Then
    57.                     List.AddItem doc.frames(i).Document.links(x).outerText
    58.                 End If
    59.             Next x
    60.         Next i
    61.     End If
    62. End Sub

    To have it navigate from web-page to web-page try this.
    VB Code:
    1. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    2.     Set doc = WebBrowser1.Document
    3.     If (pDisp Is WebBrowser1.Object) Then
    4.         If URL = "http://www.first-page.com" Then
    5.             ListAllLinks doc, List1
    6.             'ListAllLinkUrls doc, List1
    7.             WebBrowser1.Navigate "http://www.second-page.com"
    8.         Elseif URL = "http://www.second-page.com" Then
    9.             ListAllLinks doc, List1
    10.             'ListAllLinkUrls doc, List1
    11.             WebBrowser1.Navigate "http://www.third-page.com"
    12.         Elseif URL = "http://www.third-page.com" Then
    13.             ListAllLinks doc, List1
    14.             'ListAllLinkUrls doc, List1
    15.             WebBrowser1.Navigate "http://www.fourth-page.com"
    16.         End If      
    17.     End If
    18. End Sub

  3. #3
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    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

  4. #4

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    cheers!

    Bloodeye:
    I get the error ByRef type mismatch and it highlights this
    ListAllLinks doc, list1 in particular the list1 bit!

    Any ideas

  5. #5
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Did you put List1 on your form as listbox?

  6. #6

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    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!


  7. #7
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    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
  •  



Click Here to Expand Forum to Full Width