internal static LocationsInfo[] AnalyzHtml() { LocationsInfo[] lis = new LocationsInfo[15]; HtmlNode.ElementsFlags.Remove("form"); HtmlDocument h = new HtmlAgilityPack.HtmlDocument(); h.Load(Strings.HTML_PATH); for (int i = 0; i <= 15; i++) { HtmlNode hn_player = h.DocumentNode.SelectSingleNode(XPATH_PLAYER1 + (i + 3) + XPATH_PLAYER2); if (hn_player != null) { lis[i] = new LocationsInfo(); lis[i].Player = hn_player.InnerText.Replace(" ", string.Empty).Trim(); HtmlNode hn_ball = h.DocumentNode.SelectSingleNode(XPATH_BALL1 + (i + 3) + XPATH_BALL2); if (hn_ball != null) { lis[i].ballName = hn_ball.InnerText.Trim(); } HtmlNode hn_union = h.DocumentNode.SelectSingleNode(XPATH_UNION1 + (i + 3) + XPATH_UNION2); if (hn_union != null) { lis[i].union = hn_union.InnerText.Trim(); } HtmlNode hn_moon = h.DocumentNode.SelectSingleNode(XPATH_MOON1 + (i + 3) + XPATH_MOON2); if (hn_moon != null) { lis[i].HasMoon = true; } else { lis[i].HasMoon = false; } //是否度假中 Regex rx = new Regex("\\(.*\\)"); Match m = rx.Match(hn_player.InnerText); if (m.Value.Contains("u")) { lis[i].IsU = true; } else { lis[i].IsU = false; } } } HtmlNode hn_code = h.DocumentNode.SelectSingleNode(XPATH_GALAXY_CODE); GALAXY_CODE = hn_code.Attributes[2].Value; return(lis); }
private static void GalaxyLoop(string processid, int galaxyStart, int solarStart, OleDbDataAdapter adp, OleDbConnection dbc) { bool firstScan = true; for (int yin = galaxyStart - 1; yin < 9; yin++) { //第一次不完整的扫描 if (!firstScan) { solarStart = 1; } for (int tai = solarStart; tai < 500; tai++) { GalaxyScanEventHandler((yin + 1) * 10000 + tai); ha.UrlParam = "galaxyRight=dr&galaxy=" + yin + "&system=" + tai + "&galaxycode=" + LocationsInfo.GALAXY_CODE; ha.Cookies = ccold; IEnumerator ii = ccnew.GetEnumerator(); while (ii.MoveNext()) { ha.Cookies.Add((Cookie)ii.Current); } ccold = ha.Cookies; ccnew = ha.access(); LocationsInfo[] lis = LocationsInfo.AnalyzHtml(); for (int pnt = 0; pnt < lis.Length; pnt++) { if (lis[pnt] != null) { adp.InsertCommand = new OleDbCommand(@"insert into galaxymap (process, galaxy, solar, planet, punion, player, ballname, hasmoon, vacation, cdate) values ('" + processid + "','" + (yin + 1) + "','" + tai + "','" + (pnt + 1) + "','" + lis[pnt].Union + "','" + lis[pnt].Player + "','" + lis[pnt].BallName + "'," + (lis[pnt].HasMoon ? "true" : "false") + "," + (lis[pnt].IsU ? "true" : "false") + ", now())", dbc); adp.InsertCommand.ExecuteNonQuery(); } } } firstScan = false; } //扫描结束process打上结束符 adp.InsertCommand = new OleDbCommand(@"update scanprocess set complete = true where [_id] =" + processid, dbc); adp.InsertCommand.ExecuteNonQuery(); GalaxyScanEventHandler(0); }
internal static void Locations(object o) { ha = LocationsInfo.PrepareHttpAccesser(universe); //ha.Referer = referer; ha.Cookies = ccold; IEnumerator i = ccnew.GetEnumerator(); while (i.MoveNext()) { ha.Cookies.Add((Cookie)i.Current); } ccold = ha.Cookies; ccnew = ha.access(); LocationsInfo[] mylis = LocationsInfo.AnalyzHtml(); ha.AccessMethod = HttpAccesser.ACCESS_METHOD.POST; ha.AccessUrl = "http://" + universe + ".cicihappy.com/ogame/galaxy.php?mode=1"; ha.Referer = "http://" + universe + ".cicihappy.com/ogame/galaxy.php?mode=0"; //Txtout.writeA("银河系,太阳系,行星,联盟,玩家,星球名,月球,度假\r\n", "balls.csv"); string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;data source=rank.accdb"; try { using (OleDbConnection dbc = new OleDbConnection(connStr)) { dbc.Open(); OleDbDataAdapter adp = new OleDbDataAdapter(); adp.SelectCommand = new OleDbCommand(@"select max([_id]) as maxid from scanprocess where not complete", dbc); DataTable dt = new DataTable(); string processid = string.Empty; bool usecontinue; adp.Fill(dt); if (dt.Rows.Count > 0 && !dt.Rows[0][0].ToString().Equals(string.Empty)) { usecontinue = true; processid = dt.Rows[0][0].ToString(); } else { usecontinue = false; } if (usecontinue) { //找到最后一次扫描的最后一个球的坐标 -- galaxy and solar index adp.SelectCommand = new OleDbCommand(@"select top 1 galaxy, solar from (select *,galaxy * 1000 + solar as xuhao from galaxymap where process = " + processid + @")t1 order by xuhao desc", dbc); dt.Columns.Clear(); dt.Clear(); adp.Fill(dt); int galaxyStart; int solarStart; if (dt.Rows.Count == 0) { galaxyStart = 1; solarStart = 1; } else { galaxyStart = ProductivityInfo.ToInt(dt.Rows[0][0].ToString()); solarStart = ProductivityInfo.ToInt(dt.Rows[0][1].ToString()); } //根据坐标继续扫描 GalaxyLoop(processid, galaxyStart, solarStart, adp, dbc); } else { //创建一个新的扫描过程 adp.InsertCommand = new OleDbCommand(@"insert into scanprocess (complete, cdate) values (false, now())", dbc); adp.InsertCommand.ExecuteNonQuery(); adp.SelectCommand = new OleDbCommand(@"select max([_id]) as maxid from scanprocess where not complete", dbc); dt.Columns.Clear(); dt.Clear(); adp.Fill(dt); if (dt.Rows.Count > 0) { processid = dt.Rows[0][0].ToString(); //从头扫描 GalaxyLoop(processid, 1, 1, adp, dbc); } } } } catch (System.InvalidOperationException ioe) { if (ioe.ToString().Contains("OLEDB")) { MessageBox.Show(ConstString.suggest_db_conn_program_not_install); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }