views:

59

answers:

1
<div id="main">

<style type="text/css">
</style>

<script language="JavaScript">    
</script>
<p style="margin: 0pt 0pt 0.5em;"><b>Media from&nbsp;<a onclick="(new Image()).src='/rg/find-media-title/media_strip/images/b.gif?link=/title/tt0087538/';" href="/title/tt0087538/">The Karate Kid</a> (1984)</b></p>
<style type="text/css">    
</style>

<table style="border-collapse: collapse;">
</table>
</div>

I need to somehow extract the href value of the (new Image()). How exactly would I accomplish this with HtmlAgilityPack?

I'm new to it, and so far I haven't found a useful tutorial on how to effectively use it for parsing.

Thanks for the help!

A: 

HtmlAgilityPack by itself does not provide many parsing options. But you can use it with XPath to get any sort of complex parsing done. In your example you could do -

var testString = "..."; // Your html 
var doc = new HtmlDocument();
doc.LoadHtml(testString);
var node = doc.DocumentNode.SelectSingleNode("/div/p/b/a");
var hrefValue = node.GetAttributeValue("href", ""));

This will give

/title/tt0087538/
Rohit Agarwal