将图像从webbrowser复制到剪贴板

时间:2013-04-01 00:55:24

标签: vb.net image browser clipboard captcha

我需要将一个图像从一个webbrowser控件复制到我的剪贴板,因为每次重新加载时图像都会改变,我试图获取“src” - 属性并将我的picturebox.imagelocation更改为,但是图像上的图片框与webbrowser控件上的图片不同。

我正在尝试自动化Web服务,它需要填写验证码,并且每次加载页面时它都会更改,这就是我需要获取当前显示的那个的原因。

2 个答案:

答案 0 :(得分:0)

伪代码:

对于标签'img'的每个元素。获取'src'属性。启动HttpWebRequest的实例或使用WebClient.DownloadFile作为源。

您需要做一些技巧来确定源与网址的关系。例如,src可以是'/img/pony.jpg',在这种情况下,你需要从WebBrowser控件中获取url的根,使其成为'http://mylittle.com/img/pony.jpg'。

答案 1 :(得分:0)

假设您正在使用Windows窗体(如果您使用WPF需要更改获取文档的方式)并且用户未在IE区域设置中阻止剪贴板访问

Dim doc As IHTMLDocument2 = DirectCast(webBrowser1.Document.DomDocument, IHTMLDocument2)
Dim body As IHTMLElement2 = DirectCast(doc.body, IHTMLElement2)
Dim imgRange As IHTMLControlRange = DirectCast(body.createControlRange(), IHTMLControlRange)
Dim image As IHTMLControlElement = DirectCast(DirectCast(doc, IHTMLDocument3).getElementById(sImgID), IHTMLControlElement)
imgRange.add(image)
imgRange.execCommand("Copy", False, Nothing)