private List <string> BasicParse(string oriTable) { //get raw data, including Abfahrt, Ankunft, Reisedauer...uaually 3 groups List <string> result = new List <string>(); Regex reg = new Regex(@"<tr><td scope=""row"">[\s\S]*?Fahrt</span></a></p></td><td>(?<abfahrt>[\s\S]*?)</td><td>(?<ankunft>[\s\S]*?)</td><td>(?<reisedauer>[\s\S]*?)</td><td>(?<stiegsnum>[\s\S]*?)</td><td>[\s\S]*?<a href=""http://www.openstreetmap.org/copyright[\s\S]*?</tr>"); Match match = reg.Match(oriTable); while (match.Success) { fahrtInfo fi = new fahrtInfo(); fi.Abfahrt = match.Groups["abfahrt"].Value; fi.Ankunft = match.Groups["ankunft"].Value; fi.Reisedauer = match.Groups["reisedauer"].Value; fi.Umstiegnum = match.Groups["stiegsnum"].Value; summarise.Add(fi); result.Add(match.Groups[0].Value); match = match.NextMatch(); } return(result); }
private void DetailParse(List <string> oriTable) { fahrtInfo allInfo = new fahrtInfo(); List <string> singleresult = new List <string>(); List <List <string> > resultbasket = new List <List <string> >(); string resultstring = ""; foreach (string s in oriTable) { resultstring += s; } //get partial route table raw data and divide into List<List<string>>-- all umstieg info, usually 3 groups of results.Todo: combine fahrtInfo in 3 groups; Regex reg = new Regex(@"id=""partialRouteTable(?<group>[0-9])[\s\S]*?=(?:</table>)?(?:[\s\S]*?).*?(?:(?:</a></td></tr>)|(?:</a></p></td></tr></table>)|(?:</td><td /></tr></table>))"); Match match = reg.Match(resultstring); int tempcounter = 1; while (match.Success) { if (match.Groups["group"].Value == tempcounter.ToString()) { singleresult.Add(match.Groups[0].Value); match = match.NextMatch(); if (!match.Success) { resultbasket.Add(singleresult); } } else { resultbasket.Add(singleresult); singleresult = new List <string>(); tempcounter++; singleresult.Add(match.Groups[0].Value); match = match.NextMatch(); } } //parse arrival time & station names, usually 3 pairs of results--save as entity reg = new Regex(@"(<td>((?<ab>ab[\s\S]*?)|(?<an>an.+?))</td>([\s\S]*?))?\)"">(?<station>[\s\S]*?)</a>"); string type = ""; string ab = ""; string an = ""; string abstation = ""; string anstation = ""; int z = 0; foreach (List <string> sss in resultbasket) { for (int i = 0; i < sss.Count; i++) { type = stiegtypeParse(sss[i]); Match stationM = reg.Match(sss[i]); //error if (stationM.Success && stationM.Groups["ab"].Value.Length > 0) { ab = stationM.Groups["ab"].Value; abstation = stationM.Groups["station"].Value; stationM = stationM.NextMatch(); } if (stationM.Success && stationM.Groups["an"].Value.Length > 0) { an = stationM.Groups["an"].Value; anstation = stationM.Groups["station"].Value; stationM = stationM.NextMatch(); } if (stationM.Success && stationM.Groups["an"].Value.Length == 0 && stationM.Groups["ab"].Value.Length == 0) {//fussweg type = "Fussweg"; anstation = stationM.Groups["station"].Value; stationM = stationM.NextMatch(); abstation = stationM.Groups["station"].Value; stationM = stationM.NextMatch(); } fahrtUmstieg fu = new fahrtUmstieg(type, ab, an, abstation, anstation); allInfo.Umstieginfo.Add(fu); } //should change --> instead of add fahrtInfo fi = summarise[z]; fi.Umstieginfo = allInfo.Umstieginfo; summarise[z] = fi; allInfo = new fahrtInfo(); z++; } }