I am just trying to figure out webscraping in C#. Right now I am trying to retrieve the user's external IP via HTTP GET API call. I have tried multiple different sites and I have had the same System.NullReferenceException for all of them. Here is my code:
using System;
using HtmlAgilityPack;
namespace Tracer
{
class IPTracer
{
static void Main(string[] args)
{
scrape(@"http://api.ipify.org/");
}
static void scrape(string url)
{
HtmlWeb scraper = new HtmlWeb();
HtmlDocument html = scraper.Load(url);
string ip = html.DocumentNode.SelectSingleNode("/html/body/pre").InnerText;
Console.WriteLine(ip);
}
}
}
This might be a very simple mistake as I am rather new to C# but this has been bugging me for days and I have yet to find a solution. And no, I checked and "html" itself is not null.