//得到banggo上的尺码,主要用于和taobao上的尺码建立对应关系 public Dictionary <string, string> GetBSizeToTSize(HtmlDocument doc) { HtmlNode htmlNodeSizeList = doc.GetElementbyId(Resource.SysConfig_SizeListId); htmlNodeSizeList.ThrowIfNull(Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat( new StackTrace())); HtmlNodeCollection sizes = htmlNodeSizeList.SelectNodes("a"); sizes.ThrowIfNull(Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat( new StackTrace())); return(sizes.ToDictionary <HtmlNode, string, string>(sizeNode => sizeNode.InnerText.Trim(), sizeNode => null)); }
public static Dictionary <string, AsafaResult> GetTestResults(string url) { HtmlGetLogic htmlLogic = new HtmlGetLogic(); try { HtmlDocument response = htmlLogic.LoadHtmlResponse(string.Format(@"https://asafaweb.com/Scan?Url={0}", HttpUtility.UrlEncode(url))); HtmlNodeCollection nodesMatchingXPath = response.DocumentNode.SelectNodes("//div[@id='StatusSummary']/span"); return(nodesMatchingXPath != null ? nodesMatchingXPath.ToDictionary(element => element.Attributes["id"].Value.Replace("Summary", ""), element => GetStatus(element.Attributes["class"].Value)) : new Dictionary <string, AsafaResult>()); } catch (WebException) { return(new Dictionary <string, AsafaResult>()); } }
public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container) { HtmlDocument doc = container.ResponseHtml.Value; HtmlNode message = doc.DocumentNode.SelectSingleNode("//div[@class='detail_msg']"); if (message == null) { yield break; } OGameClient oClient = (OGameClient)client; // Message info int messageId = message.GetAttributeValue("data-msg-id", 0); MessageTabType tabType = MessageTabType.FleetsEspionage; string dateText = message.SelectSingleNode(".//span[contains(@class, 'msg_date')]").InnerText; DateTime date = DateTime.ParseExact(dateText, "dd.MM.yyyy HH:mm:ss", oClient.ServerCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); EspionageReport result = new EspionageReport { MessageId = messageId, TabType = tabType, Sent = new DateTimeOffset(date).Add(-oClient.Settings.ServerUtcOffset).ToOffset(oClient.Settings.ServerUtcOffset) }; // Establish location HtmlNode locationLink = message.SelectSingleNode(".//a[contains(@href, 'page=galaxy')]"); string locationType = locationLink.SelectSingleNode("./figure").GetCssClasses(s => s == "moon" || s == "planet").First(); CoordinateType coordinateType = locationType == "moon" ? CoordinateType.Moon : CoordinateType.Planet; result.Coordinate = Coordinate.Parse(locationLink.InnerText, coordinateType); // Parts HtmlNodeCollection partsNodesList = message.SelectNodes(".//ul[@data-type and not(./li[@class='detail_list_fail'])]"); Dictionary <string, HtmlNode> partsNodes = partsNodesList.ToDictionary(s => s.GetAttributeValue("data-type", "")); // Parts - Resources HtmlNode details; if (partsNodes.TryGetValue("resources", out details)) { HtmlNodeCollection values = details.SelectNodes(".//span[@class='res_value']"); Debug.Assert(values.Count == 4); var oneThousandAdd = oClient.ServerCulture.NumberFormat.NumberGroupSeparator + "000"; string[] vals = values.Select(s => s.InnerText .Replace("M", oneThousandAdd) .Replace("Bn", oneThousandAdd + oneThousandAdd)).ToArray(); Resources resources = new Resources { Metal = int.Parse(vals[0], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture), Crystal = int.Parse(vals[1], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture), Deuterium = int.Parse(vals[2], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture), Energy = int.Parse(vals[3], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture) }; result.Resources = resources; result.Details |= ReportDetails.Resources; } // Parts - Ships if (partsNodes.TryGetValue("ships", out details)) { result.DetectedShips = ParseList <ShipType>(oClient, details); result.Details |= ReportDetails.Ships; } // Parts - Defense if (partsNodes.TryGetValue("defense", out details)) { result.DetectedDefence = ParseList <DefenceType>(oClient, details); result.Details |= ReportDetails.Defense; } // Parts - Buildings if (partsNodes.TryGetValue("buildings", out details)) { result.DetectedBuildings = ParseList <BuildingType>(oClient, details); result.Details |= ReportDetails.Buildings; } // Parts - Research if (partsNodes.TryGetValue("research", out details)) { result.DetectedResearch = ParseList <ResearchType>(oClient, details); result.Details |= ReportDetails.Research; } // Return yield return(result); }