我试图使用Playwright库访问网站并下载rust中的文件,但我在web上找不到函数示例。我正在努力,但我不能从这一点上前进。完成我的代码并进行下载缺少什么?
use playwright::{Playwright, api::{Download, download}};
use tokio;
#[tokio::main]
async fn main() -> Result<(), playwright::Error> {
let playwright = Playwright::initialize().await?;
playwright.prepare()?; // Install browsers
let chromium = playwright.chromium();
let browser = chromium.launcher().headless(false).launch().await?;
let context = browser.context_builder().build().await?;
let page = context.new_page().await?;
page.goto_builder("https://demoqa.com/upload-download").goto().await?;
// playwright::api::download::Download - save_as() - suggested_filename() - url() - path()
page.click_builder("a:has-text(\"Download\")").click().await.expect("");
let my_download = page.expect_event(playwright::api::page::EventType::Download).await?;
page.wait_for_timeout(5000 as f64).await;
browser.close().await.expect("erro ao fechar navegador");
Ok(())
}
1条答案
按热度按时间yjghlzjz1#
我知道了!我希望这对将来的人有帮助...