public string monPage() { Uri uri = new Uri(DBsettings.DBURL + "mon.php"); string resp = null; //monster list doc HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); //monster detail doc //HtmlAgilityPack.HtmlDocument subdoc = new HtmlAgilityPack.HtmlDocument(); //tempary doc HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument(); //create empty table monTable = null; outHtml = ""; monUrlSet = new HashSet <string>(); monTable = _doc.CreateElement("table"); //monTable.AddClass("table table-striped table-bordered"); monTable.AppendChild(_doc.CreateElement("thead")); monTable.AppendChild(_doc.CreateElement("tbody")); var theadNode = monTable.SelectSingleNode(".//thead"); var monList = new HtmlAgilityPack.HtmlNode[] { }; var simpleCrawlResult = WebRequest.RequestAction(new RequestOptions() { Uri = uri, Method = "Get" }); //load monster list doc.LoadHtml(simpleCrawlResult); var monSpan = doc.DocumentNode.SelectSingleNode("//h5[@class='card-header']").InnerHtml; resp = monSpan; areaTab_Main = doc.DocumentNode.SelectSingleNode("//div[@id = 'Monstermon_list15']"); string tableClass = areaTab_Main.SelectSingleNode(".//table").GetAttributeValue("class", ""); monTable.AddClass(tableClass); HtmlAgilityPack.HtmlNode[] mons = areaTab_Main.SelectNodes(".//tbody/tr[position() < 5]").ToArray(); Console.Out.WriteLine("Total " + mons.Count() + " monster fetched"); //var _thead = monTable.SelectSingleNode(".//thead"); //add thead if (_thead == "") { string[] monTh = DBsettings.monTableHead; foreach (var th in monTh) { _thead += "<th>" + th + "</th>"; } theadNode.InnerHtml = _thead; } if (theadNode.InnerHtml == "") { theadNode.InnerHtml = _thead; } foreach (var mon in mons) { outHtml += monDetailPg(mon); } monTable.SelectSingleNode(".//tbody").InnerHtml += outHtml; resp += monTable.OuterHtml; return(resp); }