webbrowser 中怎么判断图片是否加载完毕
我用下面的函数会出现问题,有时间图片没有加载完毕ReadyState 就变成Complete了
Private Sub WaitUntilWebBrowserComplete(ByVal wb As WebBrowser)
Do While Not wb.ReadyState = WebBrowserReadyState.Complete
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
我需要判断这个主要是想抓取网页上的图片
我是用下面的函数抓取图片的,总是感觉到这不是最好的方法,不知道有没有其他的办法,在网上查了说可用读取缓存,但觉得这个方法也不好
Public Sub GetPhoto()
Dim sUrl As String '="要抓取图片的网址"
wb.Navigate(sUrl)
mdl.WaitUntilWebBrowserCom(wb)
Dim doc1 As HtmlDocument = wb.Document.Window.Frames(1).Document
Dim doc As mshtml.HTMLDocument
doc = doc1.DomDocument
Dim oBody As mshtml.HTMLBody = doc.body
Dim oRang As mshtml.IHTMLControlRange
oRang = oBody.createControlRange
Dim els As HtmlElementCollection
Dim el As HtmlElement
els = doc1.GetElementsByTagName("img")
For Each el In els
If InStr(el.GetAttribute("src"), "photow/aka/getphoto2?ref") > 0 Then
oRang.add(el.DomElement)
oRang.execCommand("copy", False)
' save picture
Clipboard.GetImage().Save(sPhotoPath & sId & ".jpg")
Exit For
End If
Next
End Sub