Aneiang.Pa.ZhiHu 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Aneiang.Pa.ZhiHu --version 1.0.2
                    
NuGet\Install-Package Aneiang.Pa.ZhiHu -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aneiang.Pa.ZhiHu" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aneiang.Pa.ZhiHu" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Aneiang.Pa.ZhiHu" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aneiang.Pa.ZhiHu --version 1.0.2
                    
#r "nuget: Aneiang.Pa.ZhiHu, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aneiang.Pa.ZhiHu@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aneiang.Pa.ZhiHu&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Aneiang.Pa.ZhiHu&version=1.0.2
                    
Install as a Cake Tool

<img src="assets/icon.jpg" alt="Aneiang.Pa" width="64" height="64" style="vertical-align:middle;border-radius:8px;"> Aneiang.Pa

NuGet NuGet Downloads Target Status

一个基于 .NET 的多平台热门新闻/热榜爬虫库,提供统一接口、工厂与依赖注入支持,当前内置微博、知乎、B 站、百度四个平台实现,并附带 Demo 示例。项目开源,后续将增加更多平台。

功能特性

  • 🧩 统一接口:所有爬虫实现 INewsScraper,返回 NewsResult / NewsItem
  • 🏭 可插拔工厂:通过 INewsScraperFactory + ScraperSource 获取指定爬虫
  • ⚙️ 配置驱动:Options 模式,支持自定义 URL/Cookie/User-Agent
  • 🗃️ 原始数据保留:NewsItem.ExtensionData 可存储原始响应与附加字段
  • 🔌 DI 集成:AddNewsScraper 一键注册 HttpClient、各平台爬虫与工厂

目录结构

Aneiang.Pa/
├── src/
│   ├── Aneiang.Pa.Core/        # 核心接口与模型
│   ├── Aneiang.Pa/             # 工厂与扩展方法
│   ├── Aneiang.Pa.BaiDu/       # 百度热榜实现
│   ├── Aneiang.Pa.ZhiHu/       # 知乎热榜实现
│   ├── Aneiang.Pa.Bilibili/    # B 站热搜实现
│   └── Aneiang.Pa.WeiBo/       # 微博热搜实现
└── test/
    └── Aneiang.Pa.Demo/        # 演示项目

环境要求

  • .NET SDK 8.0(运行 Demo)
  • 库目标框架:netstandard2.1(可被 .NET Core 3.1+ / .NET 5+ / .NET 8+ 引用)

安装(NuGet)

推荐聚合包(含全部平台):

dotnet add package Aneiang.Pa --version 1.0.2

按需引用单个包(示例):

dotnet add package Aneiang.Pa.WeiBo --version 1.0.2

已发布包(nuget.org,当前版本 1.0.1)

Package 版本 说明
Aneiang.Pa 1.0.2 聚合包,包含全部平台实现
Aneiang.Pa.Core 1.0.2 核心接口与模型
Aneiang.Pa.BaiDu 1.0.2 百度热榜爬虫
Aneiang.Pa.Bilibili 1.0.2 B 站热搜爬虫
Aneiang.Pa.WeiBo 1.0.2 微博热搜爬虫
Aneiang.Pa.ZhiHu 1.0.2 知乎热榜爬虫

快速开始(本地 Demo)

  1. 还原 & 构建
dotnet restore
dotnet build test/Aneiang.Pa.Demo/Aneiang.Pa.Demo.csproj
  1. 配置 test/Aneiang.Pa.Demo/appsettings.json(示例见下)

  2. 运行 Demo(默认抓取百度热榜,可修改 ScraperSource

dotnet run --project test/Aneiang.Pa.Demo

在你的项目中使用(NuGet)

using Aneiang.Pa.Data;
using Aneiang.Pa.Extensions;
using Aneiang.Pa.News;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration(cfg => cfg.AddJsonFile("appsettings.json", optional: true))
    .ConfigureServices((ctx, services) =>
    {
        // 自动注册 HttpClient、各平台爬虫与工厂
        services.AddNewsScraper(ctx.Configuration);
    })
    .Build();

using var scope = host.Services.CreateScope();
var factory = scope.ServiceProvider.GetRequiredService<INewsScraperFactory>();
var scraper = factory.GetScraper(ScraperSource.BaiDu); // WeiBo / ZhiHu / Bilibili
var result = await scraper.GetNewsAsync();
foreach (var news in result.Data)
{
    Console.WriteLine($"{news.Title} - {news.Url}");
}

配置示例(appsettings.json)

{
  "Scraper": {
    "WeiBo": {
      "BaseUrl": "https://s.weibo.com",
      "Cookie": "替换为你的 Cookie",
      "UserAgent": "Mozilla/5.0 ...",
      "NewsUrl": "/top/summary?cate=realtimehot"
    },
    "ZhiHu": {
      "NewsUrl": "https://www.zhihu.com/api/v3/feed/topstory/hot-list-web?limit=20&desktop=true"
    },
    "Bilibili": {
      "SearchUrl": "https://s.search.bilibili.com/main/hotword?limit=30"
    },
    "BaiDu": {
      "NewsUrl": "https://top.baidu.com/board?tab=realtime"
    }
  }
}

注意:SDK默认配置了,通常情况下可以不进行配置;当默认配置失效后,才会用到自定义配置。

规划与 Roadmap

  • ✅ 微博、知乎、B 站、百度热榜
  • 🚧 计划:抖音、头条、Twitter/X 等更多平台
  • 🧪 考虑:统一的重试/限流策略、更多元数据字段

贡献

  • 欢迎 PR / Issue,尤其是新增平台爬虫、改进解析与健壮性
  • 提交前请保持代码风格一致,并附带简要说明和必要的测试
  • 如果希望在 NuGet 包中发布你新增的平台,请在 Issue 先讨论方案

许可证

仓库未包含许可证文件,NuGet 当前提示缺少 License。请在使用前确认授权或补充 License(推荐添加 LICENSE 并在 Directory.Build.props 配置 <PackageLicenseExpression><PackageLicenseFile>)。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Aneiang.Pa.ZhiHu:

Package Downloads
Aneiang.Pa.News

一个基于 .NET 开箱即用的爬虫库,使用复杂度极低。项目将爬虫分为 News (热榜) 和 Sectors (特定领域) 两大类。热榜预设支持微博、知乎、B站、百度、抖音、虎扑、头条、腾讯、掘金、澎湃、凤凰网、豆瓣、CSDN、博客园、IT之家、36氪等平台。特定领域提供动态数据集爬取 (Dynamic) 和彩票数据爬取 (Lottery) 等更灵活的爬虫功能。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.7 250 1/28/2026
2.1.6 219 1/15/2026
2.1.5 225 1/15/2026
2.1.4 299 1/7/2026
2.1.2 237 1/2/2026
2.1.1 219 12/31/2025
2.1.0 224 12/29/2025
2.0.1 241 12/29/2025 2.0.1 is deprecated because it has critical bugs.
2.0.0 352 12/29/2025 2.0.0 is deprecated because it has critical bugs.
1.1.4 272 12/24/2025
1.1.3.1 228 12/22/2025
1.1.3 229 12/22/2025
1.1.2 290 12/19/2025
1.1.0 309 12/18/2025
1.0.7 226 12/13/2025
1.0.6 181 12/12/2025
1.0.5 456 12/11/2025
1.0.4 486 12/10/2025
1.0.3 493 12/10/2025
1.0.2 506 12/10/2025
Loading failed