通过VB.NET 2008的Web浏览器组件下载图像和动态和会话可维护URL



如何使用vb.net的Web浏览器控件下载嵌入式映像,我们可以通过右键单击图像并执行'将图片保存为'来实现?


我正在开发一个VB.NET项目,该项目通过特定网站爬网并下载其内容,包括嵌入其中的任何图像。现在我的问题是,我无法使用Web客户端和HTTP请求/响应类来满足我的目的,因为该网站上维护的安全性。

该网站具有一些JavaScript和jQuery的维护。此外,它通过在每个单个URL请求上跟踪的一些cookie和隐藏字段来维护会话。如果发现任何不连续性,则将其重定向到登录页面。

我通过使用Web浏览器组件找到了解决此问题的解决方案,该组件在维护安全方面非常有用。

,但是我的下一组问题是存储除HTML源文件之外的内容(如嵌入式图像),这是我目前的主要关注点,我相信许多软件开发人员必须面对相同。<<<<<<<。/strong>

我在C#中找到了我修改的各种帖子,但对我不起作用,例如 c#code in保存整个网页的代码?(带有图像/格式)

另外,我在Visual Basic 2005 中从Web-Browser Control中保存映像中有一个项目,该项目解决了相同的问题,但是为此,我的公司策略不允许我。

如何自动化右键单击的过程并"另存为"?

有真正的解决方案吗?如果没有,那么是否有任何其他解决方案,例如从临时文件夹复制。如果是,请提供解决方案!

为什么您需要实际下载图像来完成任务?另外,请记住,您实际上可以使用Web请求跟踪/发送Cookie(无需实际浏览器控件)。您可以使用htmlagilitypack来解析那些隐藏字段的HTML。

所以我建议重新访问该途径以进行自动化,而不是尝试使用浏览器控件。

我没有得到第一种方法的答案,也就是说,使用Web浏览器组件下载,但是我从"临时Internet文件"文件夹中复制了替代方案。p>这是我的代码段,正在为我完成工作。

Private Function get_Image(ByVal src As String)
    '******* code for storing Images from temporary internet files folder.......
    Dim filename As String = get_File()
    Dim gifFiles As String() = Directory.GetFiles("C:Documents and Settings123Local SettingsTemporary Internet Files", "*.*", SearchOption.AllDirectories)
    Dim imgno As Integer = 0
    For Each file As String In gifFiles
        'Dim fsi As String = Directory.GetLastWriteTime(file).ToString
        If My.Computer.FileSystem.FileExists(file) And file.Contains("attachDisplay") And Not filename.Contains("File") Then  ' This is HardCoded part for my images that are having dynamic url as my base_URL/attachDisplay?_XYZ (so in temp it is storing as attachDisplay[i]; i=1,2...)
            Dim curFileDT As Date = Directory.GetLastWriteTime(file)
            If Date.Compare(lastFileDT, curFileDT) = -1 Then ' if Last file date is before than current File write time
                imgno += 1
                My.Computer.FileSystem.CopyFile(file, filename & " Img No." & imgno & file.Substring(file.LastIndexOf(".")), True)
            End If
        End If
    Next
    lastFileDT = Date.Now 'My lastFileDT variable is declared at class level and first initialization at form load.
    '*******
End Function

这不是下载图像的正确方法,但目前正在为我完成这项工作。

最新更新