Puppeteer Sharp Node.JS Puppeteer API 的 .NET 端口开源项目

我要开发同款
匿名用户2021年12月07日
50阅读
开发技术C#
所属分类Web应用开发、网站API
授权协议MIT

作品详情

PuppeteerSharp是官方 Node.JSPuppeteerAPI 的.NET端口。

相关链接

API文档StackOverflowIssues用法截屏usingvarbrowserFetcher=newBrowserFetcher();awaitbrowserFetcher.DownloadAsync();awaitusingvarbrowser=awaitPuppeteer.LaunchAsync(newLaunchOptions{Headless=true});awaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.GoToAsync("https://www.google.com");awaitpage.ScreenshotAsync(outputFile);

可以在生成屏幕截图之前更改视口

awaitPage.SetViewportAsync(newViewPortOptions{Width=500,Height=500});生成PDF文件usingvarbrowserFetcher=newBrowserFetcher();awaitbrowserFetcher.DownloadAsync();awaitusingvarbrowser=awaitPuppeteer.LaunchAsync(newLaunchOptions{Headless=true});awaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.GoToAsync("https://www.google.com");awaitpage.PdfAsync(outputFile);注入HTMLawaitusingvarpage=awaitbrowser.NewPageAsync();awaitpage.SetContentAsync("<div>MyReceipt</div>");varresult=awaitpage.GetContentAsync();评估JavaScriptawaitusingvarpage=awaitbrowser.NewPageAsync();varseven=awaitpage.EvaluateExpressionAsync<int>("4+3");varsomeObject=awaitpage.EvaluateFunctionAsync<dynamic>("(value)=>({a:value})",5);Console.WriteLine(someObject.a);等待选择器using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync("https://www.spapage.com");awaitpage.WaitForSelectorAsync("div.main-content")awaitpage.PdfAsync(outputFile));}等待函数using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync("https://www.spapage.com");varwatchDog=page.WaitForFunctionAsync("()=>window.innerWidth<100");awaitpage.SetViewportAsync(newViewPortOptions{Width=50,Height=50});awaitwatchDog;}连接到远程浏览器varoptions=newConnectOptions(){BrowserWSEndpoint=$"wss://www.externalbrowser.io?token={apikey}"};varurl="https://www.google.com/";using(varbrowser=awaitPuppeteerSharp.Puppeteer.ConnectAsync(options)){using(varpage=awaitbrowser.NewPageAsync()){awaitpage.GoToAsync(url);awaitpage.PdfAsync("wot.pdf");}}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论