Aug 20, 2015 at 5:40 PM
Edited Aug 20, 2015 at 5:44 PM
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 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>
Aug 17 - Close
data delayed by 15 mins -
<a href="//www.google.ca/help/stock_disclaimer.html#realtime" class=dis-large>Disclaimer</a>
<div>Currency in CAD</div>
It's definitely in there. What am I missing?