PuppeteerSharpHelper.cs

(完整代码) 1KB

using Newtonsoft.Json;
using PuppeteerSharp;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace WangZheRongYao
{
    public class PuppeteerSharpHelper
    {
        /// <summary>
        /// 获取游览器对象
        /// </summary>
        public static Task<Browser> GetBrowser(int port, int height, int width)
        {
            return Puppeteer.ConnectAsync(new ConnectOptions { DefaultViewport = new ViewPortOptions() { Height = height, Width = width }, BrowserWSEndpoint = WSEndpointResponse.GetWebSocketDebuggerUrl(port) });
        }
        internal class WSEndpointResponse
        {
            public string WebSocketDebuggerUrl { get; set; }
            public static string GetWebSocketDebuggerUrl(int port)
            {
                string data;
                using (var client = new HttpClient())
                {
                    data = client.GetStringAsync($"http://127.0.0.1:{port}/json/version").Result;
                }
                return JsonConvert.DeserializeObject<WSEndpointResponse>(data).WebSocketDebuggerUrl;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。