Am having an HTML document and from that want to fetch necessary information so have used HTML agility concept. Using the following code am getting all the necessary data.
var web = new HtmlWeb();
var doc = web.Load("http://www.talentsearchpeople.com/en/jobs/?page=joblisting&pubID=&formID=&start=0&count=8&module=&functionLevel1=&provinceNode=&countryNode=&keyword=");
var nodes = doc.DocumentNode.SelectNodes("//a[@class='grijs'][@title]");
foreach (var node in nodes)
{
HtmlAttribute att = node.Attributes["title"];
title = att.Value;
Response.Write("<br/>" + att.Value);
}
var Location = doc.DocumentNode.SelectNodes("//td[@width='80']");
foreach (var node in Location)
{
if (node.InnerHtml.Contains("Location:"))
{
locationname = HttpUtility.HtmlDecode(node.NextSibling.NextSibling.InnerText.Trim());
Response.Write("<br/>Location1=" + locationname);
}
}
Using the above code am getting following output:
** Lead Buyer South
Customer Service Order Management with native level of German
EMEA Customer Experience & Quality Internship
Service Desk Team Leader with Excellent Level of German and French
Sourcing & Procurement Consultant with native level of French
Jefe/a de ventas con alemán e inglés. Recien Titulados.
Jefe/a de ventas con alemán e inglés. Recien Titulados.
Jefe/a de ventas con alemán e inglés. Recien Titulados.
Location1=Almeria
Location1=Terrassa
Location1=United Kingdom, Manchester
Location1=Barcelona
Location1=Barcelona
Location1=A Coruña
Location1=Cataluña
Location1=Murcia **
Above code works correctly for fetching of the data. Problem is i want to insert above data in database and also want to display the data in correct format means first title of the property followed by its location **Lead Buyer South Location1=Almeria
Customer Service Order Management with native level of German Location1=Terrassa
EMEA Customer Experience & Quality Internship Location1=United Kingdom, Manchester
Service Desk Team Leader with Excellent Level of German and French Location1=Barcelona
Sourcing & Procurement Consultant with native level of French Location1=Barcelona
Jefe/a de ventas con alemán e inglés. Recien Titulados. Location1=A Coruña
Jefe/a de ventas con alemán e inglés. Recien Titulados. Location1=Cataluña
Jefe/a de ventas con alemán e inglés. Recien Titulados. Location1=Murcia**
Alternative Method by searching the table tag
var web = new HtmlWeb();
var doc = web.Load("http://www.talentsearchpeople.com/en/jobs/?page=joblisting&pubID=&formID=&start=0&count=8&module=&functionLevel1=&provinceNode=&countryNode=&keyword=");
var mainNode = doc.DocumentNode.SelectNodes("//table[@class='border-jobs']/*");
foreach (var mainNodes in mainNode)
{
string pathdet = mainNodes.XPath;
var nodes = mainNodes.SelectSingleNode("//a[@class='grijs'][@title]");
if (nodes != null)
{
HtmlAttribute att = nodes.Attributes["title"];
title = att.Value;
Response.Write("<br/>" + att.Value);
}
var Description = doc.DocumentNode.SelectSingleNode("//td[@colspan='2']");
if (Description.InnerHtml.Contains("Description:"))
{
s = Description.InnerHtml;
s = s.Replace("Description:", "");
Response.Write("<br/>Description=" + s);
}
var Location = doc.DocumentNode.SelectSingleNode("//td[@width='80']");
if (Location.InnerHtml.Contains("Location:"))
{
locationname = HttpUtility.HtmlDecode(Location.NextSibling.NextSibling.InnerText.Trim());
Response.Write("<br/>Location1=" + locationname);
}
}
If i use the above code then i get following output:
Assistant Call Centre Manager with fluent level of Spanish and English
Description= We are recruiting an Assistant Call Center Manager for a multinational company based in Lisboa, Portugal. This person will be responsible for the team management. Experience in team management, mainly in contact center, environment is required.
Location1=Lisboa, Portugal
I get the above output 8 times as //table[@class='border-jobs']/* tag occurs 8 times in the document
how can i get correct output?