public static void writefile(calendarevent cevent, string dist) { StreamWriter file = new StreamWriter(dist); file.WriteLine(cevent.Googleevent.Summary); file.WriteLine(cevent.Googleevent.Start.DateTimeRaw); file.WriteLine(cevent.Googleevent.End.DateTimeRaw); file.WriteLine(cevent.Googleevent.Location); file.Dispose(); }
public static calendarevent Parse(string url, string file, string query) { HtmlWeb webclient = new HtmlWeb(); HtmlDocument doc = null; try { doc = webclient.Load(url + file + query, "GET"); } catch (System.Net.WebException e) { Console.WriteLine(e); throw; } HtmlNode titlenode = doc.DocumentNode.SelectSingleNode("/html/body/table[1]//tr/td//table[2]//tr/td[3]/table[2]//tr/td/table//tr[2]//text()"); string title; if (titlenode != null) { title = titlenode.InnerText; title = title.Replace(" ", " "); } else throw new ArgumentNullException(); HtmlNodeCollection speakernodes = doc.DocumentNode.SelectNodes("/html/body/table[1]//tr/td//table[2]//tr/td[3]/table[2]//tr/td/table//tr[3]/td[2]//text()"); string speaker_name = speakernodes[0].InnerText.Replace(" ", " "); string speaker_institute = speakernodes[1].InnerText; speaker_institute = speaker_institute.Replace(" ", " "); string date = doc.DocumentNode.SelectSingleNode("/html/body/table[1]//tr/td//table[2]//tr/td[3]/table[2]//tr/td/table//tr[4]/td[2]").InnerText; string time = doc.DocumentNode.SelectSingleNode("/html/body/table[1]//tr/td//table[2]//tr/td[3]/table[2]//tr/td/table//tr[5]/td[2]").InnerText; string venue = doc.DocumentNode.SelectSingleNode("/html/body/table[1]//tr/td//table[2]//tr/td[3]/table[2]//tr/td/table//tr[6]/td[2]").InnerText; venue = venue.Replace(" ", " "); calendarevent newevent = new calendarevent(); newevent.set_location(venue); newevent.set_starttime(date, time, "Hongkong"); newevent.set_endtime(date, time, "Hongkong"); newevent.set_summary(title); newevent.set_discription(speaker_name, speaker_institute); return newevent; }