Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 450

New Post: Difficulty with XPath to get a single result

$
0
0
I'm not yet very familiar with XPath, but what I'm trying to do shouldn't be this difficult. Basically, I'm periodically checking Google finance to see what the current stock price of a few companies. It's nothing fancy, but I've hit a wall.

When I read the html, I can see the price is kept in a node with the id called 'price-panel'. Should be easy, but I'm getting an error when I try to get the node.
string url = "http://www.google.ca/finance?q="+Symbol;
var getHtmlWeb = new HtmlWeb();
var document = getHtmlWeb.Load(url);

var node = document.DocumentNode.SelectNodes("//[@id='price-panel']");
At this point, the following exception gets thrown:
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
Taking a quick peek at the HTML from right now, it looks like this:
<div id=price-panel class="id-price-panel goog-inline-block">
<div>
<span class="pr">
<span id="ref_16234934_l">2.70</span>
</span>
<div class="id-price-change nwp">
<span class="ch bld"><span class="chr" id="ref_16234934_c">-0.05</span>
<span class="chr" id="ref_16234934_cp">(-1.82%)</span>
</span>
</div>
</div>
<div>
<span class=nwp>
Aug 17 - Close
</span>
<div class=mdata-dis>
<span class=dis-large><nobr>CVE
data delayed by 15 mins -
<a href="//www.google.ca/help/stock_disclaimer.html#realtime"  class=dis-large>Disclaimer</a>
</nobr></span>
<div>Currency in CAD</div>
</div>
</div>
</div>
It's definitely in there. What am I missing?

Viewing all articles
Browse latest Browse all 450

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>