半肾
精华
|
战斗力 鹅
|
回帖 0
注册时间 2018-4-5
|
大约10-15分钟用Rust写了一个,答案是不麻烦,诀窍是使用现代的编程语言
- use regex::Regex;
- use std::{fs::File, io::Write};
- const BASE: &str = "http://167.71.246.232:8080/rabbit_hole.php";
- #[tokio::main]
- async fn main() {
- let re =
- Regex::new(r"(?i)\[(?P<loc>\d+),\s*'(?P<byte>[0-9a-f]{2})'\]\s*(?P<next>.+)").unwrap();
- let mut next = BASE.to_string();
- let mut data = Vec::new();
- for count in 1.. {
- let body = reqwest::get(&next).await.unwrap().text().await.unwrap();
- match re.captures(&body) {
- Some(cap) => {
- data.push((
- usize::from_str_radix(&cap["loc"], 10).unwrap(),
- u8::from_str_radix(&cap["byte"], 16).unwrap(),
- ));
- next = format!("{}?page={}", BASE, &cap["next"]);
- }
- None => {
- break;
- }
- }
- if count % 100 == 0 {
- println!("block: {}", count);
- }
- }
- data.sort_by_key(|&(loc, _)| loc);
- let bytes: Vec<_> = data.into_iter().map(|(_, byte)| byte).collect();
- let mut file = File::create("rabbit.png").unwrap();
- file.write_all(&bytes).unwrap();
- }
复制代码
依赖有:
- [dependencies]
- regex = "1.4.3"
- reqwest = "0.11.0"
- tokio = { version = "1.2.0", features = ["rt-multi-thread", "macros"] }
复制代码
flag: automation_is_handy
|
|