public static List<Payload> Parse(string source) { var payloads = new List<Payload>(); // 1. // Find all matches in file. var payloadMatches = Regex.Matches(source, @"(<a.*?>.*?</a>)", RegexOptions.Singleline); // 2. // Loop over each match. foreach (Match payloadMatch in payloadMatches) { var payloadMatchValue = payloadMatch.Groups[1].Value; // 3. Declare new object to contain parsed link name title. var payload = new Payload(); // 4. // Get href attribute. var linkMatch = Regex.Match(payloadMatchValue, @"href=\""(.*?)\""", RegexOptions.Singleline); if (!linkMatch.Success) continue; var path = HttpUtility.HtmlDecode(linkMatch.Groups[1].Value); payload.Link = "https://github.com" + path; // 5. // Remove inner tags from text. var name = Regex.Replace(payloadMatchValue, @"\s*<.*?>\s*", "", RegexOptions.Singleline); payload.Name = name; payloads.Add(payload); } return payloads; }
public string GetCodeFromPayload(Payload payload) { var source = _client.DownloadString(payload.Link); if (source.Contains("<code>")) return GetBetween(source, "<code>", "</code>"); if (source.Contains("<pre>")) return GetBetween(source, "<pre>", "</pre>"); return string.Empty; }