Skip to content

Commit 05b0eeb

Browse files
committed
using v2ex api
1 parent 714ffb9 commit 05b0eeb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Meowv.Blog.BackgroundWorkers/Workers/HotWorker.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public override async Task Execute(IJobExecutionContext context)
7171
{
7272
switch (source)
7373
{
74-
case Hot.KnownSources.juejin or Hot.KnownSources.csdn or Hot.KnownSources.zhihu or Hot.KnownSources.huxiu or Hot.KnownSources.douyin or Hot.KnownSources.woshipm or Hot.KnownSources.kaiyan:
74+
case Hot.KnownSources.v2ex or Hot.KnownSources.juejin or Hot.KnownSources.csdn or Hot.KnownSources.zhihu or Hot.KnownSources.huxiu or Hot.KnownSources.douyin or Hot.KnownSources.woshipm or Hot.KnownSources.kaiyan:
7575
{
7676
using var client = _httpClient.CreateClient();
7777
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66");
@@ -163,17 +163,17 @@ async Task SaveAsync()
163163

164164
case Hot.KnownSources.v2ex:
165165
{
166-
var html = result as HtmlDocument;
167-
var nodes = html.DocumentNode.SelectNodes("//span[@class='item_title']/a").ToList();
166+
var json = result as string;
167+
var nodes = JArray.Parse(json);
168168

169-
nodes.ForEach(x =>
169+
foreach (var node in nodes)
170170
{
171171
hot.Datas.Add(new Data
172172
{
173-
Title = x.InnerText,
174-
Url = $"https://www.v2ex.com{x.GetAttributeValue("href", "")}"
173+
Title = node["title"].ToString(),
174+
Url = node["url"].ToString()
175175
});
176-
});
176+
}
177177

178178
await SaveAsync();
179179
break;

src/Meowv.Blog.Core/Domain/Hots/Hot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static class KnownSources
8080
public static Dictionary<string, string> Dictionary { get; set; } = new Dictionary<string, string>
8181
{
8282
{ cnblogs, "https://www.cnblogs.com" },
83-
{ v2ex, "https://www.v2ex.com/?tab=hot" },
83+
{ v2ex, "https://www.v2ex.com/api/topics/hot.json" },
8484
{ segmentfault, "https://segmentfault.com/hottest" },
8585
{ weixin, "https://weixin.sogou.com" },
8686
{ douban, "https://www.douban.com/group/explore" },

0 commit comments

Comments
 (0)