C# - 下载由 mshtml 加载的图片

本文关键字:加载 mshtml 下载 | 更新日期: 2023-09-27 18:31:01

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

因此,我打开一个Internet Explorer并使用mshtml和SHDocVw进行导航。(登录未询问,因为已记住)

我可以导航到一个网址,其中只有图片,但找不到如何下载它。

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

有人有解决方案吗?

提前感谢您的帮助。

问候。

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

头像是我的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)

C# - 下载由 mshtml 加载的图片

嗨,

这是我用来从 Web 浏览器控件复制验证码图像而无需导航到图像 url 或引用页面的一个函数,您需要根据需要更改图像参数

没有为头像指定任何html标签,因此我无法编辑完全适合您需求的以下功能,

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