I'm trying to create an app that navigates and downloads images from web sites. (This is my first Windows App, so perhaps I'm in over my head.)
I have quite a few problems working with AxWebBrowser and mshtml.HTMLDocument. I'll just post one problem here:
Navigation is extremely quirky. I had it working to some extent: It would navigate and download images from some page while skipping over other pages. Now, it's only downloading the first page. Here's some relevant code:
I have quite a few problems working with AxWebBrowser and mshtml.HTMLDocument. I'll just post one problem here:
Navigation is extremely quirky. I had it working to some extent: It would navigate and download images from some page while skipping over other pages. Now, it's only downloading the first page. Here's some relevant code:
Code:
Public Function Crawl()
If LvUrls.Items(lviIndex).Checked Then
Dim doc As mshtml.HTMLDocument
Try
doc = ReadWebDoc(DownloadLink, LvUrls.Items(lviIndex))
If Not doc Is Nothing Then
[COLOR=green]' get files[/color]
LoadFiles(doc)
[COLOR=green]' get links[/color]
LoadLinks(doc)
doc.close()
doc = Nothing
End If
Catch ex As Exception
Dim m As String = ex.Message
End Try
End If
End Function
Public Sub LoadLinks(ByVal MyHtml As mshtml.HTMLDocument)
Dim x As Int32 = (MyHtml.links.length - 1)
'Dim f As Int32 = (MyHtml. - 1)
Dim y As Int32 = 0
If CurrLevel < MaxLevel Then
CurrLevel += 1
For y = 0 To (x)
Try
[COLOR=green]' here i add links to my listview and
' a separate thread loops through the
' listview items and crawls each
' one: Crawl() above[/color]
Catch ex As Exception
Dim m As String = ex.Message
End Try
Next y
End If
Public Function ReadWebDoc(ByVal DownloadLink As String, ByVal Lvi As ListViewItem) As mshtml.HTMLDocument
[COLOR=green]' wait to load doc[/color]
Dim doc As New mshtml.HTMLDocument
Try
Lvi.SubItems(3).Text = "Downloading..."
myBrowser.Navigate(DownloadLink)
[COLOR=green]' the first page works here, but all
' subsequent pages never get "busy" here:[/color]
Do Until Not myBrowser.Busy
Loop
doc = DirectCast(myBrowser.Document, mshtml.HTMLDocument)
Catch ex As Exception
Lvi.SubItems(3).Text = ex.Message
End Try
Return doc
End Function