Html Agility Pack (HAP) is a free and open-source HTML parser written in C# to read/write DOM and supports plain XPATH or XSLT. It is a .NET code library that allows you to parse "out of the web" HTML files.
I found html file with a comment "Use 2 alternating methods of displaying tax due to confuse screen scrapers".
I need to pull out the 'Assessed Tax:' value from there.
I used two different versions of XPATH but they don't work:
//ul[@id='cphMainContent_cphRightColumn_taxDue2']/li[2]
//*[contains(text(),'Assessed Tax:')]/ancestor::li[1]/following-sibling::li[1]
var filepath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "notfoundTpage.html");
var doc=new HtmlDocument();
doc.Load(filepath);
var node=doc.DocumentNode.SelectSingleNode("//ul[@id='cphMainContent_cphRightColumn_taxDue2']/li[2]");
if (node == null)
{
Console.WriteLine("XPATH not found 1");
}
node = doc.DocumentNode.SelectSingleNode("//*[contains(text(),'Assessed Tax:')]/ancestor::li[1]/following-sibling::li[1]");
if (node == null)
{
Console.WriteLine("XPATH not found 2");
}`
1. Description
I found html file with a comment "Use 2 alternating methods of displaying tax due to confuse screen scrapers". I need to pull out the 'Assessed Tax:' value from there. I used two different versions of XPATH but they don't work: //ul[@id='cphMainContent_cphRightColumn_taxDue2']/li[2] //*[contains(text(),'Assessed Tax:')]/ancestor::li[1]/following-sibling::li[1]
`
2. Exception
3. Fiddle or Project
Tester.zip `using HtmlAgilityPack;
var filepath=Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "notfoundTpage.html"); var doc=new HtmlDocument(); doc.Load(filepath); var node=doc.DocumentNode.SelectSingleNode("//ul[@id='cphMainContent_cphRightColumn_taxDue2']/li[2]"); if (node == null) { Console.WriteLine("XPATH not found 1"); }
node = doc.DocumentNode.SelectSingleNode("//*[contains(text(),'Assessed Tax:')]/ancestor::li[1]/following-sibling::li[1]"); if (node == null) { Console.WriteLine("XPATH not found 2"); }`
4. Any further technical details
.NET 7.0 HtmlAgilityPack 1.11.57
Hello @ovolkov ,
The changes we made in the v1.11.57 has been reverted yesterday.
I just upgraded your project to the v1.11.58 and everything work fine again.
Let me know if that's fixed for you.
Best Regards,
Jon
Thanks! Everything is working fine!
пн, 29 січ. 2024 р., 15:53 користувач Jonathan Magnan < @.***> пише: