0

I want to get text from URL but text is not shown in source code. I can see it only in inspect element . Is there anyway, in C# to get the contents of Inspect element of the page. I try htmlagilitypack with c# but give null exception.

This is html code in inspect element:

<a id="href933" class="op-to-b-2" href="http://bux20.com/viewads/17EDB5BB6D1H7CVB69C55E7U554B5575EZ6H6O9524333CB46133315509H53735Z77444D5645OE4743136O967055276UV63933" target="_blank" i="933">

My C# code:

HtmlNodeCollection nodes1 = doc.DocumentNode.SelectNodes("//a[@class='op-to-b-2'][@href]");
M.Tajari
  • 59
  • 11
  • I've answered as best I can, but it's worth noting that your C# code isn't even valid - you've tried to include `"` within a string literal with no escaping. – Jon Skeet Mar 12 '14 at 11:26

1 Answers1

0

I haven't used the HTML Agility pack myself, but I suspect it's just that your XPath expression is wrong. Try:

doc.DocumentNode.SelectNodes("//a[@class='op-to-b-2']/@href")

That will get name/value pairs. To get just the values, you can use:

doc.DocumentNode.SelectNodes("string(//a[@class='op-to-b-2']/@href)")
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194