This repository has been archived by the owner on Jul 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.rs
62 lines (57 loc) · 1.86 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use chromiumoxide::browser::{Browser, BrowserConfig};
use chromiumoxide::cdp::browser_protocol::page::CaptureScreenshotFormat;
use chromiumoxide::page::ScreenshotParams;
use futures::StreamExt;
use std::time::Duration;
use tokio::time::sleep;
#[cfg(target_os = "windows")]
const CHROME_PATH: &str = "./chrome_win_x64/chrome.exe";
#[cfg(target_os = "linux")]
const CHROME_PATH: &str = "./chrome_linux_x64/chrome";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (mut browser, mut handler) = Browser::launch(
BrowserConfig::builder()
.chrome_executable(CHROME_PATH)
.with_head()
.incognito()
.args(["--headless=new"])
.viewport(None)
.build()?,
)
.await?;
let handle = tokio::task::spawn(async move {
while let Some(h) = handler.next().await {
if h.is_err() {
break;
}
}
});
let page = browser
.new_page("https://buzkaaclicker.pl/download/essa") // cf turnstile challenge
.await?;
page.wait_for_navigation().await?;
// wait for turnstile to load, do something better than that
sleep(Duration::from_secs(5)).await;
let html = page.content().await?;
println!("Waf html?: {html}");
if !html.contains("challenges.cloudflare.com") {
panic!("no waf challenge");
}
let turnstile = page.find_element("iframe").await?;
page.click(turnstile.clickable_point().await?).await?;
sleep(Duration::from_secs(5)).await;
let html = page.content().await?;
println!("New html: {html}");
page.save_screenshot(
ScreenshotParams::builder()
.format(CaptureScreenshotFormat::Png)
.full_page(true)
.build(),
"example.png",
)
.await?;
browser.close().await?;
let _ = handle.await;
Ok(())
}