My code fails at printing and throws out a NullReferenceException was unhandled at this line while scraping from the table at http://signalspremium.com/trading-resources-information-center/?tmpl=component. Please note at this point I am not logging in to the website.I just need to get the data as is.
foreach (var row in Table.SelectNodes("tbody/tr"))
My Code is
- using System.Text;
- using System.Threading.Tasks;
- using ScrapySharp.Network;
- using HtmlAgilityPack;
- using ScrapySharp.Extensions;
-
- namespace Scrapping
- {
- class Program
- {
- static void Main(string[] args)
- {
- ScrapingBrowser Browser = new ScrapingBrowser();
- Browser.AllowAutoRedirect = true;
- Browser.AllowMetaRedirect = true;
-
- WebPage PageResult = Browser.NavigateToPage(new Uri("http://signalspremium.com/trading-resources-information-center/?tmpl=component"));
- HtmlNode TableNode = PageResult.Html.CssSelect(".stable").First();
-
-
- var Table = PageResult.Html.CssSelect(".stable").First();
-
- List<string> Names = new List<string>();
- foreach (var row in Table.SelectNodes("tbody/tr"))
- {
- foreach (var cell in row.SelectNodes("th"))
- {
- Names.Add(cell.InnerText);
- Console.WriteLine(Names);
- Console.ReadLine();
- }
- }
-
-
- }
- }
- }
HTML content I am tryint to retrive so i can store in a db table
- <table class="stable" style="width:100%;"><tbody><tr><th style="background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">NAME</th>
- <th style="background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">RATE</th>
- <th style="text-align:center;background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">DATE</th>
- <th style="text-align:center;background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">TIME</th>
- <th style="text-align:center;background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">DIRECTION</th>
- <th style="text-align:center;background: #444444;color: white;color: #EE9900;font-family: sans-serif;font-size: 1em; padding: 10px;">EXPIRY</th></tr><tr style="background:#ececec;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">EUR/USD</td><td style="padding: 10px;">1.11500</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 23:00 GMT</td></tr><tr style="background:#fff;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">GBP/USD</td><td style="padding: 10px;">1.25180</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 20:00 GMT</td></tr><tr style="background:#ececec;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">USD/JPY</td><td style="padding: 10px;">103.08900</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 23:00 GMT</td></tr><tr style="background:#fff;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">EUR/GBP</td><td style="padding: 10px;">0.89060</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 21:00 GMT</td></tr><tr style="background:#ececec;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">AUD/USD</td><td style="padding: 10px;">0.76800</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 23:30 GMT</td></tr><tr style="background:#fff;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">USD/CHF</td><td style="padding: 10px;">0.96700</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 21:00 GMT</td></tr><tr style="background:#ececec;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">GOLD</td><td style="padding: 10px;">1,304.10</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 20:00 GMT</td></tr><tr style="background:#fff;color:#8e44ad;font-weight:bold;"><td style="padding: 10px;">SILVER</td><td style="padding: 10px;">18.41</td><td style="text-align:center;padding: 10px;">05/11/2016</td><td style="text-align:center;padding: 10px;">12:30 GMT</td><td style="text-align:center;"><br><a href="http://signalspremium.com/login">LOG IN TO SEE THE SIGNALS<p></p></a></td><td style="text-align:center;"> 20:00 GMT</td></tr></tbody></table>