mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 13:58:08 +00:00
create playwright-rust
This commit is contained in:
parent
785fe1a122
commit
aa1ba85751
7 changed files with 1770 additions and 0 deletions
1
playwright-rust/.gitignore
vendored
Normal file
1
playwright-rust/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target
|
1660
playwright-rust/Cargo.lock
generated
Normal file
1660
playwright-rust/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
playwright-rust/Cargo.toml
Normal file
12
playwright-rust/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "playwright-rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
playwright = "0.0.20"
|
||||
tokio = { version = "1.39.3", features = ["full"] }
|
||||
|
||||
[[bin]]
|
||||
name = "playwright-rust"
|
||||
path = "main.rs"
|
18
playwright-rust/main.rs
Normal file
18
playwright-rust/main.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use playwright::Playwright;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), playwright::Error> {
|
||||
let playwright = Playwright::initialize().await?;
|
||||
playwright.prepare()?;
|
||||
let chromium = playwright.chromium();
|
||||
let browser = chromium.launcher().launch().await?;
|
||||
let context = browser.context_builder().build().await?;
|
||||
let page = context.new_page().await?;
|
||||
page.goto_builder("https://example.com/").goto().await?;
|
||||
let s: String = page.eval("() => location.href").await?;
|
||||
println!("{}", s);
|
||||
page.click_builder("a").click().await?;
|
||||
let s: String = page.eval("() => location.href").await?;
|
||||
println!("{}", s);
|
||||
Ok(())
|
||||
}
|
11
playwright/main.ts
Normal file
11
playwright/main.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { chromium } from "playwright";
|
||||
|
||||
const browser = await chromium.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto("https://example.com/");
|
||||
const l1 = await page.evaluate(() => location.href);
|
||||
console.log(l1);
|
||||
await page.click("a");
|
||||
const l2 = await page.evaluate(() => location.href);
|
||||
console.log(l2);
|
||||
await browser.close();
|
56
playwright/package-lock.json
generated
Normal file
56
playwright/package-lock.json
generated
Normal file
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"name": "playwright",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"playwright": "^1.46.1"
|
||||
}
|
||||
},
|
||||
"node_modules/fsevents": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.46.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz",
|
||||
"integrity": "sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.46.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.46.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.1.tgz",
|
||||
"integrity": "sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
playwright/package.json
Normal file
12
playwright/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node --experimental-transform-types main.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"playwright": "^1.46.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.7.0"
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue