This is a library that scrapes the Melon Chart in .NET - Top 100, Hot 100, Daily 100, Weekly 100 and Monthly 100
$ dotnet add package MelonChart.NETThis is the Melon chart scraping library written in .NET - Top 100, Hot 100, Daily 100, Weekly 100 and Monthly 100
Install the NuGet package of this library.
dotnet add package MelonChart.NET
You may need to run the following command to install Playwright dependencies.
pwsh bin/Debug/net8.0/playwright.ps1 install
Use the library in your code.
var chart = new Top100Chart();
var collection = await chart.GetChartAsync();
foreach (var item in collection.Items)
{
Console.WriteLine($"{item.Rank} - {item.Title} by {item.Artist}");
}
If you want to get the Hot 100 chart, use the Hot100Chart class.
var chart = new Hot100Chart();
var collection = await chart.GetChartAsync();
foreach (var item in collection.Items)
{
Console.WriteLine($"{item.Rank} - {item.Title} by {item.Artist}");
}
You can also register all the charts and get the chart by the type.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKeyedScoped<IChart, Top100Chart>(ChartTypes.Top100);
builder.Services.AddKeyedScoped<IChart, Hot100Chart>(ChartTypes.Hot100);
builder.Services.AddKeyedScoped<IChart, Daily100Chart>(ChartTypes.Daily100);
builder.Services.AddKeyedScoped<IChart, Weekly100Chart>(ChartTypes.Weekly100);
builder.Services.AddKeyedScoped<IChart, Monthly100Chart>(ChartTypes.Monthly100);
var app = builder.Build();
app.MapGet("/top100", async ([FromKeyedServices(ChartTypes.Top100)] IChart chart) =>
{
var collection = await chart.GetChartAsync();
return Results.Json(collection.Items);
});
app.MapGet("/hot100", async ([FromKeyedServices(ChartTypes.Hot100)] IChart chart) =>
{
var collection = await chart.GetChartAsync();
return Results.Json(collection.Items);
});
app.MapGet("/daily100", async ([FromKeyedServices(ChartTypes.Daily100)] IChart chart) =>
{
var collection = await chart.GetChartAsync();
return Results.Json(collection.Items);
});
app.MapGet("/weekly100", async ([FromKeyedServices(ChartTypes.Weekly100)] IChart chart) =>
{
var collection = await chart.GetChartAsync();
return Results.Json(collection.Items);
});
app.MapGet("/monthly100", async ([FromKeyedServices(ChartTypes.Monthly100)] IChart chart) =>
{
var collection = await chart.GetChartAsync();
return Results.Json(collection.Items);
});