0

我必须从网站获取头像图片而不向我的应用程序用户询问凭据。只有一个先决条件,用户在运行应用程序之前在 Internet Explorer 中记住他的凭据。

因此,我打开 Internet Explorer 并使用 mshtml 和 SHDocVw 进行导航。(因为记住了,所以没有要求登录)

我可以导航到唯一内容是图片的网址,但找不到如何下载它。

在我的 HtlmDocument 中找到一个 mshtml.HTMLImg 但无法检索图片流。

有人有解决方案吗?

提前感谢您的帮助。

问候。

编辑:找到类似的东西将图像数据放入剪贴板

//头像是我的mshtml.HTMLImg

mshtml.IHTMLElement2 body2 = (mshtml.IHTMLElement2)doc.body;

mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)body2.createControlRange();

controlRange.add((mshtml.IHTMLControlElement)avatar);

controlRange.execCommand("Copy", false, System.Reflection.Missing.Value); controlRange.remove(0);

但是这段代码在 exec 命令上被阻塞了……没有错误,但卡在了这一行。

(信息:使用 Internet Explorer 10)

4

1 回答 1

0

hi here is a one function I am using to copy captcha images form webbrowser control without navigating to image url or refersh page ,You need to change the image parameters as per your need

U have not specified any html tag for Avatar so I am unable to edit following function which exactly suit ur need,

Private Function copyImageToClipBoard() As String
    Dim doc As mshtml.IHTMLDocument2 = DirectCast(wc.Document.DomDocument, mshtml.IHTMLDocument2)
    Dim imgRange As mshtml.IHTMLControlRange = DirectCast(DirectCast(doc.body, mshtml.HTMLBody).createControlRange(), mshtml.IHTMLControlRange)

    For Each img As mshtml.IHTMLImgElement In doc.images
        imgRange.add(DirectCast(img, mshtml.IHTMLControlElement))
        If img.src.Contains("recaptcha/api/image?c=") Or img.src.Contains("seccode.php") Then
            imgRange.execCommand("Copy", False, Nothing)
            If isManual = True Then
                Using bmp As Bitmap = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
                    Dim ofrmCap As New frmCaptcha(bmp)
                    ofrmCap.BringToFront()
                    ofrmCap.ShowDialog()
                    mCaptcha = vars.mCaptcha
                    vars.mCaptcha = Nothing
                End Using
            Else
                bgwDecaptcher.RunWorkerAsync(Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
            End If
        End If

    Next
    Return mCaptcha
End Function
于 2013-09-12T08:53:19.930 回答