Skip to content

Instantly share code, notes, and snippets.

Last active April 12, 2020 13:55
What would you like to do?
class Program
static void Main(string[] args)
var titles = GetTitles("Category:日本語の姓");
File.WriteAllText("日本語の姓.txt", string.Join("\r\n", titles), Encoding.UTF8);
private static List<string> GetTitles(string cmtitle)
var titles = new List<string>();
var client = new RestClient("") {ThrowOnAnyError = true};
string cmcontinue = null;
var request = new RestRequest("api.php", DataFormat.Json)
.AddParameter("action", "query")
.AddParameter("list", "categorymembers")
.AddParameter("cmprop", "title") // タイトルのみ取得
.AddParameter("format", "json")
.AddParameter("cmlimit", "500")
.AddParameter("cmtitle", cmtitle);
if (cmcontinue != null)
request.AddParameter("cmcontinue", cmcontinue);
var response = client.Get(request);
var o = JObject.Parse(response.Content);
titles.AddRange(o["query"]?["categorymembers"].Select(x => x["title"].ToString()));
cmcontinue = o["continue"]?["cmcontinue"]?.ToString();
} while (cmcontinue != null);
return titles;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment