views:

38

answers:

0

Working with HTML Agility Pack in C#. Running the following code on a site I know should return some values keeps coming up blank. Can anyone see what I'm doing wrong here?

 public Dictionary<string, string> linkMiner(string site)
    {
        Dictionary<string, string> links = new Dictionary<string, string>();
        url = site;
        string target = String.Format("http://{0}", url);
        string result = String.Empty;
        try
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(target);
            request.Method = "GET";
             using (var stream = request.GetResponse().GetResponseStream())
             using (var reader = new StreamReader(stream, Encoding.UTF8))
             {
                 result = reader.ReadToEnd();
             }

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.Load(new StringReader(result));
            HtmlAgilityPack.HtmlNode root = doc.DocumentNode;
            foreach (HtmlAgilityPack.HtmlNode link in root.SelectNodes("//a"))
            {
                links.Add(link.OuterHtml, link.InnerText);
            }
            return links;

And I'm calling the method like so:

Miner miner = new Miner();
Dictionary<string, string> lines = miner.linkMiner(targetBox.Text);
foreach (KeyValuePair<string, string> pair in lines)
     {
         resultsBox.AppendText(pair + System.Environment.NewLine);
     }