Created
December 9, 2015 00:31
-
-
Save naveensrinivasan/58fa8eb57e61535f10db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var keywords = new[] { "GET", "DELETE", "PATCH", "POST" }; | |
var document =new HtmlDocument(); | |
document .LoadHtml( | |
(new HtmlWeb() | |
.Load("https://developer.github.com/v3/") | |
.DocumentNode.SelectSingleNode("/html[1]/body[1]/div[3]/div[2]/div[1]").ChildNodes | |
.Select(cn => cn.InnerHtml) | |
.Where(cn => !string.IsNullOrEmpty(cn.Trim())) | |
.First())); | |
var dictionary = document.DocumentNode.SelectNodes("//a") | |
.Select(p => new | |
{ | |
Key = p.GetAttributeValue("href", "not found").Replace("/v3", ""), | |
Value = "https://developer.github.com" + p.GetAttributeValue("href", "not found") | |
}) | |
.Where(p => p.Key.Trim() != "#" & p.Key.Trim() != "/") | |
.ToDictionary(p => p.Key, p => p.Value) | |
.OrderBy(p => p.Key); | |
var newapis = new Func<string, IEnumerable<string>>((url) => | |
{ | |
try | |
{ | |
return new HtmlWeb() | |
.Load(url) | |
.DocumentNode.SelectSingleNode("//*[@id=\"wrapper\"]/div[1]").SelectNodes("//pre") | |
.Select(dn => dn.InnerText) | |
.Where(cn => keywords | |
.Contains( | |
Regex.Split(cn, "[^a-zA-Z]+").First() /*split first word*/)).ToList(); | |
} | |
catch (Exception ex) | |
{ | |
return new[] {""}; | |
} | |
}); | |
//these things don't have any API's - troubleshooting, versions,/activity/events/types/, auth | |
dictionary.ToObservable() | |
.Select(d => new {Key = d.Key, Values = newapis(d.Value) }) | |
.Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment