我在C#中创建了一个小的Playwright程序,它提交一个Url,在返回的文档上找到一个按钮,选择该文档上的一个按钮并"点击"它。如果我使用Fiddler,我可以看到"点击"会生成一个POST,显示返回了JSON,但我似乎找不到任何允许我返回此JSON的Playwrist方法或例程。以下是片段:
IPlaywright playwright = await Playwright.CreateAsync();
IBrowser browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = true
});
IBrowserContext context = await browser.NewContextAsync();
IPage page = await context.NewPageAsync();
await page.GotoAsync(some_url);
IElementHandle button = await page.QuerySelectorAsync("a[id^='date-filter-update']");
if (button != null)
{
await button.ClickAsync();
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
string response = await page.ContentAsync(); // <= returns HTML and I need JSON
}
有人能帮我从"等待页面"获得"回复"吗。ContentAsync((;'返回我在Fiddler中看到的JSON?
看看这个。您可以在Playwright中收听response
和request
网络事件。
page.on('response', response =>
console.log(response.json()));
嗯。。尽管那些微不足道的文件、例子或解释迫使我进行无休止的不必要的测试、扭曲和跳跃,但我最终还是成功了。。。