public Task(int lat, int lon) { _inFileName = "input\\"; if (lat < 0) _inFileName += "-"; else _inFileName += "+"; if (Math.Abs(lat) < 10) _inFileName += "0" + Math.Abs(lat); else _inFileName += "" + Math.Abs(lat); _inFileName += ","; if (lon < 0) _inFileName += "-"; else _inFileName += "+"; if (Math.Abs(lon) < 10) _inFileName += "00" + Math.Abs(lon); else { if (Math.Abs(lon) < 100) _inFileName += "0" + Math.Abs(lon); else _inFileName += "" + Math.Abs(lon); } _inFileName += ".html"; Reaper reaper = new Reaper((new StreamReader(_inFileName).ReadToEnd())); _lat = Convert.ToDouble(reaper.RemainAfterFirst("<br>Latitude <b>").RemainBeforeFirst("</b>").GetResult()[0]); _lon = Convert.ToDouble(reaper.RemainAfterFirst("<br>Longitude <b>").RemainBeforeFirst("</b>").GetResult()[0]); }
public Task(int lat, int lon) { _inFileName = "input\\"; if (lat < 0) { _inFileName += "-"; } else { _inFileName += "+"; } if (Math.Abs(lat) < 10) { _inFileName += "0" + Math.Abs(lat); } else { _inFileName += "" + Math.Abs(lat); } _inFileName += ","; if (lon < 0) { _inFileName += "-"; } else { _inFileName += "+"; } if (Math.Abs(lon) < 10) { _inFileName += "00" + Math.Abs(lon); } else { if (Math.Abs(lon) < 100) { _inFileName += "0" + Math.Abs(lon); } else { _inFileName += "" + Math.Abs(lon); } } _inFileName += ".html"; Reaper reaper = new Reaper((new StreamReader(_inFileName).ReadToEnd())); _lat = Convert.ToDouble(reaper.RemainAfterFirst("<br>Latitude <b>").RemainBeforeFirst("</b>").GetResult()[0]); _lon = Convert.ToDouble(reaper.RemainAfterFirst("<br>Longitude <b>").RemainBeforeFirst("</b>").GetResult()[0]); }
public bool 提取() { StringWriter strWriter = new StringWriter(); //TimeSpan repearTime = new TimeSpan(); string originString = (new StreamReader(_inFileName)).ReadToEnd(); //处理重大漏洞:HTML代码中,部分行名是包含在</tr>\n<tr><td align=\"center\">中,而大多数是包含在</tr>\n<tr><td>中 originString = originString.Replace("</tr>\n<tr><td align=\"center\">", "</tr>\n<tr><td>"); //DateTime startTime = DateTime.Now; Reaper reaper = new Reaper(originString); string latStr = reaper.RemainAfterFirst("<br>Latitude <b>").RemainBeforeFirst("</b>").GetResult()[0]; string lonStr = reaper.RemainAfterFirst("<br>Longitude <b>").RemainBeforeFirst("</b>").GetResult()[0]; //repearTime += DateTime.Now - startTime; strWriter.Write("LATLON:"); strWriter.WriteLine(latStr + " " + lonStr); //startTime = DateTime.Now; foreach (Reaper part in reaper.RemainBeforeFirst("<table width=\"100%\" summary=\"table used for formatting\"><tr><td>").ReapByProfix("<hr><big><b><i>")) { string partName = part.RemainBeforeFirst(":</i></b></big>").GetResult()[0]; //ShowStrings(part.RemainBeforeFirst(":</i></b></big>").GetResult()); foreach (Reaper table in part.ReapByProfix("<div align=\"center\"><table border=1 summary=\"")) { string tableName = table.RemainBeforeFirst("\" width=\"95%\">").GetResult()[0]; int lineCount = 0; foreach (Reaper line in table.ReapByProfix("<tr><td>").GiveUpContain("<td>Jan</td><td>Feb</td><td>Mar</td>")) { string lineName = line.RemainBeforeFirst("</td>").GetResult()[0]; //repearTime += DateTime.Now - startTime; strWriter.WriteLine("PART:" + partName); strWriter.WriteLine("TABLE:" + tableName); strWriter.WriteLine("LINE:" + lineName); strWriter.WriteLine("NUM:" + ++lineCount); strWriter.Write("DATA:"); //startTime = DateTime.Now; foreach (Reaper data in line.ReapByProfix("<td align=\"center\" nowrap>").RemainBeforeFirst("</td>")) { //repearTime += DateTime.Now - startTime; strWriter.Write(data.GetResult()[0] + " "); //startTime = DateTime.Now; } strWriter.WriteLine(); } } } //处理HTML的转义符 string result = strWriter.ToString(); result = result.Replace("<", "<"); result = result.Replace(">", ">"); result = result.Replace("°", "°"); //处理Average Daily Temperature Range 多出的* result = result.Replace("* ", ""); try { StreamWriter _outFile = new StreamWriter(_outFileName); _outFile.Write(result); _outFile.Close(); } catch (Exception ex) { Program.errLog.WriteLine(ex.Message); Program.errLog.Flush(); } //Console.WriteLine("完成:" + _inFileName + " -> " + _outFileName); //Console.WriteLine("Reaper\n耗时" + repearTime); return(true); }
public bool 提取() { StringWriter strWriter = new StringWriter(); //TimeSpan repearTime = new TimeSpan(); string originString = (new StreamReader(_inFileName)).ReadToEnd(); //处理重大漏洞:HTML代码中,部分行名是包含在</tr>\n<tr><td align=\"center\">中,而大多数是包含在</tr>\n<tr><td>中 originString = originString.Replace("</tr>\n<tr><td align=\"center\">", "</tr>\n<tr><td>"); //DateTime startTime = DateTime.Now; Reaper reaper = new Reaper(originString); string latStr = reaper.RemainAfterFirst("<br>Latitude <b>").RemainBeforeFirst("</b>").GetResult()[0]; string lonStr = reaper.RemainAfterFirst("<br>Longitude <b>").RemainBeforeFirst("</b>").GetResult()[0]; //repearTime += DateTime.Now - startTime; strWriter.Write("LATLON:"); strWriter.WriteLine(latStr + " " + lonStr); //startTime = DateTime.Now; foreach (Reaper part in reaper.RemainBeforeFirst("<table width=\"100%\" summary=\"table used for formatting\"><tr><td>").ReapByProfix("<hr><big><b><i>")) { string partName = part.RemainBeforeFirst(":</i></b></big>").GetResult()[0]; //ShowStrings(part.RemainBeforeFirst(":</i></b></big>").GetResult()); foreach (Reaper table in part.ReapByProfix("<div align=\"center\"><table border=1 summary=\"")) { string tableName = table.RemainBeforeFirst("\" width=\"95%\">").GetResult()[0]; int lineCount = 0; foreach (Reaper line in table.ReapByProfix("<tr><td>").GiveUpContain("<td>Jan</td><td>Feb</td><td>Mar</td>")) { string lineName = line.RemainBeforeFirst("</td>").GetResult()[0]; //repearTime += DateTime.Now - startTime; strWriter.WriteLine("PART:" + partName); strWriter.WriteLine("TABLE:" + tableName); strWriter.WriteLine("LINE:" + lineName); strWriter.WriteLine("NUM:" + ++lineCount); strWriter.Write("DATA:"); //startTime = DateTime.Now; foreach (Reaper data in line.ReapByProfix("<td align=\"center\" nowrap>").RemainBeforeFirst("</td>")) { //repearTime += DateTime.Now - startTime; strWriter.Write(data.GetResult()[0] + " "); //startTime = DateTime.Now; } strWriter.WriteLine(); } } } //处理HTML的转义符 string result = strWriter.ToString(); result = result.Replace("<", "<"); result = result.Replace(">", ">"); result = result.Replace("°", "°"); //处理Average Daily Temperature Range 多出的* result = result.Replace("* ", ""); try { StreamWriter _outFile = new StreamWriter(_outFileName); _outFile.Write(result); _outFile.Close(); } catch(Exception ex) { Program.errLog.WriteLine(ex.Message); Program.errLog.Flush(); } //Console.WriteLine("完成:" + _inFileName + " -> " + _outFileName); //Console.WriteLine("Reaper\n耗时" + repearTime); return true; }