如何使用Htmlagilitypack从网页获取图像 [英] How Do I Get Image From Webpage With Htmlagilitypack

查看:381
本文介绍了如何使用Htmlagilitypack从网页获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是HtmlAgilityPack中的新手,但是我试着用它从网页上获取图片。到目前为止,这是我的代码,但是没有工作,我正在寻找页面的大列表图像中心。你能帮我吗?

Hello , im new in HtmlAgilityPack but im trying get image from webpage with it.Here is my code so far but isnt working, im traying to get big list image center of the page.Could u help me please ?

Imports System.Net
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim req As WebRequest = WebRequest.Create("https://www.sportoto.gov.tr/spor-toto-liste.aspx")
        Dim doc = New HtmlAgilityPack.HtmlDocument
        Using res As WebResponse = req.GetResponse()
            doc.Load(res.GetResponseStream())
        End Using

        Dim nodes As HtmlAgilityPack.HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@id='contentLeft']")
        For Each node As HtmlAgilityPack.HtmlNode In nodes
            Dim link As HtmlAgilityPack.HtmlNode = node.SelectSingleNode("./div[@id='listimg']/img")
            Dim att As HtmlAgilityPack.HtmlAttribute = link.Attributes("src")
            PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(att.Value)))
        Next
    End Sub
End Class

推荐答案

通常我会建议您在 [ ^ ]类似问题的解决方案。



但问题是listimgDIV最初没有图像,它添加了JavaScript,所以很遗憾你不能使用HtmlAgilityPack,因为它只是一个HTML解析器而且无法解释JavaScript。

你需要的是WebBrowser控件 [ ^ ]。
Usually I would advise you something like shown in this[^] solution to a similar question.

But the problem is that 'listimg' DIV initially does not have an image, it is added with JavaScript, so unfortunately you cannot use HtmlAgilityPack because it is only a HTML parser and it's unable to interpret the JavaScript.
What you need is WebBrowser control[^].


这篇关于如何使用Htmlagilitypack从网页获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆