[RESOLVED] Navigate to Hyperlink -- VB6
Hey Guyz....
I was writing a code on VB6 to download the picture albums of my friends on Facebook. I have written the code to save the images currently being displayed on the web page(Webbrowser1).
But I am facing a Problem....I need to navigate to the next picture....How ??
I was thinking that if the code navigates to the HREF(link) behind the "Next" hyperlink on the page....my code would run.
So I need your help on HOW to Click on the "Next" or the "Previous" hyperlink on the WebBrowser component.
<ul class="pagerpro"><li class="pagerpro_li"><a href="/photo.php?pid=406412&id=1342142580" id="photonav_prev" class="pagerpro_a">Previous</a></li><li class="pagerpro_li"><a href="/photo.php?pid=8388&id=1342142580" id="photonav_next" class="pagerpro_a">Next</a></li></ul></div></div>
Thank You in advance.
Re: Navigate to Hyperlink -- VB6
Something like this should work...
Code:
Private Function FindNextLinkUrl() As String
Dim CollectionOfLinks As Object, Link As Object
Set CollectionOfLinks = WB.Document.getelementsbytagname("A")
For Each Link In CollectionOfLinks
If UCase(Link.innertext) = UCase("next") Then
FindNextLinkUrl = Link.href
Exit For
End If
Next Link
End Function
However, it is untested as I could not think of a site that had a next link on it. I guess I need more caffine...
Good Luck
Re: Navigate to Hyperlink -- VB6
Facebook has a next link !!!! but yeah...ill try it.....!!!
Re: Navigate to Hyperlink -- VB6
Doesnt work !!!!! No errors in the code though....!!!! Nothing Happens !!!
Re: Navigate to Hyperlink -- VB6
It is not for navigation, it is for finding the link so you can navigate to it via WB.Navigate FindNextLinkUrl and I don't book nor do I tweet!!!
Good Luck
Re: Navigate to Hyperlink -- VB6
i aktually tryed 2 navigate it....i still din get the required link.
Re: Navigate to Hyperlink -- VB6
Well, have you tried debug.print to see if it returns any result? Have you used F8 to step through the code to see how and if it works? Have you tested the values to see if you might also need to add a trim() function because "next" and " next " do not equal each other? Because this works...
Code:
Option Explicit
Private Sub Form_Load()
Command1.Enabled = False
Me.Visible = True
NavigateWebBrowser "http://www.vbforums.com/forumdisplay.php?f=1"
Command1.Enabled = True
End Sub
Private Sub NavigateWebBrowser(LinkToNavTo As String)
WB.Navigate LinkToNavTo
Do While WB.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
End Sub
Private Sub Command1_Click()
'Navigate to Hyperlink -- VB6
Dim CollectionOfLinks As Object, Link As Object
Set CollectionOfLinks = WB.Document.body.getelementsbytagname("A")
For Each Link In CollectionOfLinks
If Trim(UCase(Link.innertext)) = Trim(UCase("Navigate to Hyperlink -- VB6")) Then
NavigateWebBrowser CStr(Trim(Link.href))
Exit For
End If
Next
End Sub
Good Luck
Re: Navigate to Hyperlink -- VB6
Amazing.....this code works...thnx !!!!