playwright = await Playwright.CreateAsync();
var userDataDir = $"{Directory.GetCurrentDirectory()}\\UserData";
var context = await playwright.Chromium.LaunchPersistentContextAsync(userDataDir,
new BrowserTypeLaunchPersistentContextOptions
{
Headless = false,
ViewportSize = new ViewportSize()
{
Width = 1920,
Height = 1080
}
//Args = new List<string> { "--start-maximized" }
}
);
page = context.Pages[0];
await page.GotoAsync("https://www.cnblogs.com/");
var links = await page.EvaluateAsync(@"Array.from(document.querySelectorAll('.post-item-body div > a')).map(a => a.href)");
//var links = await page.EvaluateAsync<IEnumerable<Class1>>(@"Array.from(document.querySelectorAll('.post-item-body div > a')).map(a => a.href)");
var str = "";
foreach (var item in JsonSerializer.Deserialize<IEnumerable<Class1>>(links.Value))
{
str += $"{item.s}\r\n";
}
textBox1.Text = str;
public class Class1
{
public string s { get; set; }
}
标签:PlayWright,links,await,page,item,var,Net,EvaluateAsync From: https://www.cnblogs.com/dacong/p/18513278