I have a working statement in PHP using the simple dom parser that I want to convert into C# using the HTML Agility Pack.
I am really struggling and have not been able to get anything even close to working.
Here is the HTML I am working on: http://www.amazon.com/gp/offer-listing/B002UYSHMM/
Here is my PHP DOM Parser code that I want to convert to C#:
foreach($html->find('div.resultsset table tbody.result tr') as $article)
{
if($article->find('span.price', 0))
{
// get retail
$item[$retail.$i++] = $article->find('span.price', 0)->plaintext;
// get soldby
if($article->find('img', 0)->getAttribute('alt') <> '')
{
$item[$soldby.$j++] = $article->find('ul.sellerInformation img', 0)->getAttribute('alt');
}
else
{
$item[$soldby.$j++] = $article->find('ul.sellerInformation li a b', 0)->plaintext;
}
$ret['SellerInfo'] = $item;
}
}
If anyone can help I would really appreciate it!
I’ve never used CSS selectors with HTMLAgilityPack but using xpath (which works similarly, but with a different syntax) it works like such:
Thats about it really. You can use LINQ to handle collections when you’re not using SelectSingleNode(). So to take your example and put it in practice:
If you need some help grabbing the XPath of a specific dom element there is a great firefox plugin named XPath Checker that will instantly get you the XPath of any dom element by right clicking. Its been very useful for me working with HTMLAgilityPack.