求助:VB6.0利用WebBrowser获取动态图片遇到个问题,见内=>
我在VB6.0中通过WebBrowser控件通过以下代码获取图片:'没有frame的情况PrivateSubGetImg()DimdocAsHTMLDocumentDim...
我在VB6.0中通过WebBrowser控件通过以下代码获取图片:
'没有frame的情况
Private Sub GetImg()
Dim doc As HTMLDocument
Dim body As HTMLBody
Dim range As IHTMLControlRange
Dim img As IHTMLControlElement
Set doc = WebBrowser1.Document
Set body = doc.body
Set range = body.createControlRange
Set img = doc.images("checkcodeimg")
Clipboard.Clear
range.Add img
range.execCommand ("copy")
Picture1.Picture = Clipboard.GetData
Set img = Nothing
Set range = Nothing
Set body = Nothing
Set doc = Nothing
End Sub
如果图片没有包含在frame中,通过上面的函数可以成功获取到图片;
如果图片包含在frame中,通过下面的函数:
Private Sub GetImageFromWeb2()
Dim doc As Object
Set doc = WebBrowser1.Document
Dim body As HTMLBody
Set body = doc.body
Dim img As IHTMLControlElement
Set img = WebBrowser1.Document.frames("checkcodeframe").Document.images("checkcodeimg")
Dim range As Object
Set range = WebBrowser1.Document.body.createControlRange()
range.Add img
range.execCommand "Copy", False, Null
Set img = Nothing
Set range = Nothing
Me.Picture3.Picture = Clipboard.GetData()
Clipboard.Clear
End Sub
在该函数执行到range.Add img时出现错误“参数无效”,参看两个函数中的img变量都是一样的,类型也相同,而且都有有效值,不知道是什么原因,麻烦解答一下,谢谢!
网页示例:
//index.htm
<HTML><HEAD><TITLE>Example</TITLE>
<BODY>
<IFRAME style="WIDTH: 64px; HEIGHT: 23px" align=top marginHeight=1 id=checkcodeframe
src="CheckCode.htm" frameBorder=0 scrolling=no
height=23>
</IFRAME>
</BODY></HTML>
//CheckCode.htm
<HTML><HEAD></HEAD>
<BODY><IMG id=checkcodeimg src="CA324VND.gif"></BODY></HTML> 展开
'没有frame的情况
Private Sub GetImg()
Dim doc As HTMLDocument
Dim body As HTMLBody
Dim range As IHTMLControlRange
Dim img As IHTMLControlElement
Set doc = WebBrowser1.Document
Set body = doc.body
Set range = body.createControlRange
Set img = doc.images("checkcodeimg")
Clipboard.Clear
range.Add img
range.execCommand ("copy")
Picture1.Picture = Clipboard.GetData
Set img = Nothing
Set range = Nothing
Set body = Nothing
Set doc = Nothing
End Sub
如果图片没有包含在frame中,通过上面的函数可以成功获取到图片;
如果图片包含在frame中,通过下面的函数:
Private Sub GetImageFromWeb2()
Dim doc As Object
Set doc = WebBrowser1.Document
Dim body As HTMLBody
Set body = doc.body
Dim img As IHTMLControlElement
Set img = WebBrowser1.Document.frames("checkcodeframe").Document.images("checkcodeimg")
Dim range As Object
Set range = WebBrowser1.Document.body.createControlRange()
range.Add img
range.execCommand "Copy", False, Null
Set img = Nothing
Set range = Nothing
Me.Picture3.Picture = Clipboard.GetData()
Clipboard.Clear
End Sub
在该函数执行到range.Add img时出现错误“参数无效”,参看两个函数中的img变量都是一样的,类型也相同,而且都有有效值,不知道是什么原因,麻烦解答一下,谢谢!
网页示例:
//index.htm
<HTML><HEAD><TITLE>Example</TITLE>
<BODY>
<IFRAME style="WIDTH: 64px; HEIGHT: 23px" align=top marginHeight=1 id=checkcodeframe
src="CheckCode.htm" frameBorder=0 scrolling=no
height=23>
</IFRAME>
</BODY></HTML>
//CheckCode.htm
<HTML><HEAD></HEAD>
<BODY><IMG id=checkcodeimg src="CA324VND.gif"></BODY></HTML> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询