从特定网页Div获取图像标签 [英] Fetch images tags from a specific webpage Div

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

问题描述

我正在尝试从网页中的特定div获取图像标记。这是网页链接链接



我用过这段代码:

I am trying to fetch images tags from a specific div in a web page. Here is the web page link link

I have used this code:

var webGet = new HtmlWeb(); 
var document = webGet.Load(txt.Text);
var infos = from info in document.DocumentNode.SelectNodes("//div[@class='ui-box-body']")
            from link in info.SelectNodes("img").Where(x => x.Attributes.Contains("src"))
            select new 
            {
                LinkURL = link.Attributes["src"].Value
            };
lbl.Text = infos.ToString();



但它返回null值。请告诉我这段代码有什么不对。在此先感谢


but it returns null value. Please tell me whats wrong in this code. Thanks in advance

推荐答案

HtmlWeb web = new HtmlWeb();

HtmlAgilityPack.HtmlDocument document = web.Load(url);

var rateNode =来自document.DocumentNode.SelectNodes中的信息(// div [@ class ='class name'])

来自info.SelectNodes中的链接(/ /img\").Where(x=>x.Attributes.Contains(\"src))

选择新的

{

link .Attributes [src]。价值

};



//返回查看(lstRecords);





字符串结果;

lbl.Text = rateNode.ToString();

foreach(var a in rateNode)

{

int count = 0;

Image img = new Image();



img.ID = count +a;

count ++;



img.ImageUrl = a .Value

Controls.Add(img);

}
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument document = web.Load(url);
var rateNode = from info in document.DocumentNode.SelectNodes("//div[@class='class name']")
from link in info.SelectNodes("//img").Where(x=>x.Attributes.Contains("src"))
select new
{
link.Attributes["src"].Value
};

// return View(lstRecords);


string result;
lbl.Text = rateNode.ToString();
foreach (var a in rateNode)
{
int count=0;
Image img = new Image();

img.ID = count + "a";
count++;

img.ImageUrl = a.Value
Controls.Add(img);
}


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

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