47 lines
1.4 KiB
C#
Raw Normal View History

2024-12-16 21:23:13 +00:00
using HtmlAgilityPack;
using System;
using System.Linq;
2024-12-17 11:10:58 +00:00
using AngleSharp;
2024-12-16 21:23:13 +00:00
2024-12-17 11:10:58 +00:00
class DrApi
{
2024-12-16 21:23:13 +00:00
2024-12-17 11:10:58 +00:00
public static async Task<List<string>> DomQueryClass(string htmlContent, string className)
{
var config = Configuration.Default;
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(req => req.Content(htmlContent));
var elements = document.QuerySelectorAll($".{className}");
2024-12-16 21:23:13 +00:00
2024-12-17 11:10:58 +00:00
return elements.Select(el => el.TextContent).ToList(); //OuterHtml).ToList()
}
public static async Task<string> get_rants(string url)
{
string response = await HTTP.get(url).ConfigureAwait(false); ;
2024-12-16 21:23:13 +00:00
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(response);
2024-12-17 11:10:58 +00:00
var nodes = await DomQueryClass(response, "rantlist-title-text");
foreach (var node in nodes)
{
Console.WriteLine(node);
}
//var nodes = doc.DocumentNode.SelectNodes("//a");
2024-12-16 21:23:13 +00:00
//var nodes = doc.DocumentNode.SelectNodes("//a[contains(@class,'rantlist-content-col')");
//var nodes = doc.DocumentNode.SelectNodes("//div[contains(@class, 'rant-comment-row-widget')]");
2024-12-17 11:10:58 +00:00
//foreach (var node in nodes) {
// Console.WriteLine(node.GetAttributeValue("class","None"));
// if(node.GetAttributeValue("class","None") == "rantlist-bglink"){
2024-12-16 21:23:13 +00:00
2024-12-17 11:10:58 +00:00
// Console.WriteLine(node.InnerText);
//}
//}
2024-12-16 21:23:13 +00:00
return null;
}
}