Created
July 11, 2018 09:20
-
-
Save mayur-tendulkar/2f524b373a05a45ffec12ac356fc68e5 to your computer and use it in GitHub Desktop.
AZR-ListAllAzureServicesNew
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Fetching service listing..."); | |
Console.ReadKey(); | |
Task.Run(async () => FetchRecords()); | |
Console.ReadKey(); | |
} | |
static async void FetchRecords() | |
{ | |
var client = new HttpClient(); | |
var data = await client.GetStringAsync("https://azure.microsoft.com/en-us/services/"); | |
var doc = new HtmlAgilityPack.HtmlDocument(); | |
doc.LoadHtml(data); | |
var node = doc.DocumentNode.SelectNodes("//div").ToList(); | |
var listOfServices = new List<AzureServices>(); | |
var lb = new StringBuilder(); | |
foreach (var item in node) | |
{ | |
if (item?.Attributes["class"]?.Value == "column medium-6 end") | |
{ | |
var service = new AzureServices(); | |
var a = item.SelectNodes("a").FirstOrDefault(); | |
service.ServiceName = a.InnerText; | |
service.ServiceURL = a.Attributes["href"].Value; | |
lb.AppendLine(service.ServiceName + ", https://azure.microsoft.com" + service.ServiceURL); | |
listOfServices.Add(service); | |
} | |
} | |
var file = System.IO.File.Create( | |
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), | |
"AzureListing1.txt")); | |
file.Close(); | |
File.WriteAllText(file.Name, lb.ToString()); | |
file.Close(); | |
} | |
} | |
public class AzureServices | |
{ | |
public string ServiceName { get; set; } | |
public string ServiceURL { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment