Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
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();

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

1 solution

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);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900