using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCheck_Click(object sender, EventArgs e)
{
string webaddress = "";
string name = "";
string votes = "";
string line = "";
using (WebClient client = new WebClient())
{
client.DownloadFile(@"http://www.mobilityawarenessmonth.com/local-heroes/?icp=1&ihpp=3900", @"C:\\NMEDA\\list.html");
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(@"C:\\NMEDA\\list.html");
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
{
HtmlAttribute att = link.Attributes["href"];
if (att.Value.ToString().Contains("entrant"))
{
webaddress = att.Value.ToString();
using (WebClient client2 = new WebClient())
{
client2.DownloadFile(@webaddress, @"C:\\NMEDA\\file.html");
}
using (StreamReader reader = new StreamReader(@"C:\\NMEDA\\file.html"))
{
while ((line = reader.ReadLine()) != null)
{
if (line.Contains("votecountvotes"))
{
votes = line.ToString();
}
if (line.Contains(@"in the 2014 National Mobility Awareness Month Local Hero contest! "))
{
name = line.ToString();
}
}
}
// Tidy Votes
votes = votes.Trim();
string[] v = votes.Split('<');
votes = v[0].ToString();
votes = votes.Replace(",", "");
// Tidy entrant name
name = name.Trim();
string[] ent = name.Split('-');
name = ent[0].ToString();
name = name.Replace("Vote for ", "");
txtResults.AppendText(votes + " | " + name + " | " + webaddress + "\r\n");
}
}
doc.Save("C:\\NMEDA\\list.html");
}
}
}