Automation.Playwright
1.58.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Automation.Playwright --version 1.58.0
NuGet\Install-Package Automation.Playwright -Version 1.58.0
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="Automation.Playwright" Version="1.58.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Automation.Playwright" Version="1.58.0" />
<PackageReference Include="Automation.Playwright" />
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 Automation.Playwright --version 1.58.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Automation.Playwright, 1.58.0"
#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 Automation.Playwright@1.58.0
#: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=Automation.Playwright&version=1.58.0
#tool nuget:?package=Automation.Playwright&version=1.58.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PlaywrightAutomation
PlaywrightAutomation 是一个为 .NET 应用封装的 Playwright 库,便于通过依赖注入与托管服务在应用中执行浏览器自动化 / 测试任务。
安装
dotnet add package Automation.Playwright --version 1.*.*
快速开始(示例)
下面示例展示了典型的注册与使用方式,基于 Program.cs / Startup.cs 和一个控制器示例。
Program.cs(或 Startup.cs):
var builder = WebApplication.CreateBuilder(args);
// 注册 Playwright 服务
builder.AddPlaywrightDefaults();
builder.Services.AddControllers();
var app = builder.Build();
app.MapControllers();
app.Run();
示例控制器:
[ApiController]
[Route("[controller]/[action]")]
public class PlaywrightController(
ILogger<PlaywrightController> logger,
IPlaywrightService playwrightService) : ControllerBase
{
/// <summary>
/// 获取指定 URL 的元素内容
/// </summary>
/// <param name="url">目标 URL</param>
/// <param name="selector">CSS 选择器</param>
/// <param name="attribute">属性名称(如 html 或 text)</param>
/// <returns>元素内容</returns>
[HttpGet]
public async Task<IActionResult> GetElement(string url, string selector, string attribute)
{
try
{
var result = await playwrightService.GetElement(url, selector, string.Empty, attribute: attribute);
return Ok(result);
}
catch (Exception ex)
{
logger.LogError(ex, "获取元素内容失败");
return StatusCode(500, $"获取元素内容失败: {ex.Message}");
}
}
}
许可证
本项目使用 MIT 许可证(详见 LICENSE.txt)。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- DecoratR (>= 1.4.0)
- Microsoft.Extensions.Hosting (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Playwright (>= 1.58.0)
-
net8.0
- DecoratR (>= 1.4.0)
- Microsoft.Extensions.Hosting (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Options (>= 10.0.3)
- Microsoft.Playwright (>= 1.58.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
切换核心版本,新增独立的browser控制