public ActionResult Index() { string strUrl = "http://rate.bot.com.tw/Pages/Static/UIP003.zh-TW.htm"; //Html AgilityPack WebClient client = new WebClient(); currency currency = new currency(); using (MemoryStream ms = new MemoryStream(client.DownloadData(strUrl))) { HtmlDocument doc = new HtmlDocument(); doc.Load(ms, Encoding.UTF8); // 取得所有符合條件的nodes HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//table[2]/tr[@class='color0' or @class='color1' ]");///tr[contains(@class='color0')] td[@class='titleLeft'] currency.dtCurrency = new DataTable(); currency.dtCurrency.Columns.Add("幣別"); currency.dtCurrency.Columns.Add("買入"); currency.dtCurrency.Columns.Add("賣出"); currency.NewTime = doc.DocumentNode.SelectSingleNode("//div[@class='entry-content']/table/tr/td[2]").InnerText.Trim().Replace("\r\n", "").Replace(" ",""); List<CheckBoxes> CurrencyType = new List<CheckBoxes>(); foreach (HtmlNode node in nodes) { DataRow r = currency.dtCurrency.NewRow(); r[0] = node.SelectSingleNode("td[@class='titleLeft']").InnerText.Replace(" ",""); if (r[0].ToString() == "美金 (USD)" || r[0].ToString() == "英鎊 (GBP)" || r[0].ToString() == "日圓 (JPY)" || r[0].ToString() == "人民幣(CNY)") { CurrencyType.Add(new CheckBoxes() { Text = r[0].ToString(), Checked = true }); }else { CurrencyType.Add(new CheckBoxes() { Text = r[0].ToString(), Checked = false }); } r[1] = node.SelectSingleNode("td[3]").InnerText; r[2] = node.SelectSingleNode("td[4]").InnerText; currency.dtCurrency.Rows.Add(r); currency.CurrencyType = CurrencyType; } } return View(currency); } public class CheckBoxes { public string Text { get; set; } public bool Checked { get; set; } } public class currency { public string Name { get; set; } public double buy { get; set; } public double sale { get; set; } public List<CheckBoxes> CurrencyType { get; set; } public string NewTime{ get; set; } public DataTable dtCurrency { get; set; } }