Skip to content

Instantly share code, notes, and snippets.

@kuttsun
Last active October 29, 2016 15:39
Show Gist options
  • Save kuttsun/891bb81a89641de6d682e508e67a4765 to your computer and use it in GitHub Desktop.
Save kuttsun/891bb81a89641de6d682e508e67a4765 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Net;
using System.IO;
using HtmlAgilityPack;
namespace GetGitHubReleases
{
class Program
{
static void Main(string[] args)
{
// HtmlAgilityPack では直接URLのデータを取得できないようなので、
// WebClient を使用して取得する
using (WebClient webClient = new WebClient())
using (Stream stream = webClient.OpenRead("ここにURLを書く"))
{
var html = new HtmlDocument();
// ページを取得
html.Load(stream);
// spanタグのやつの中で
var nodes = html.DocumentNode.Descendants("span")
// class が css-truncate-target のやつを取得し
.Where(node => node.GetAttributeValue("class", string.Empty).Contains("css-truncate-target"))
// タグの中身を取得
.Select(node => node.InnerHtml);
// 取得したタグの中身を順に表示
foreach (var version in nodes)
{
Console.WriteLine(version);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment