Requests2
A Rust library the crate help you Write a function similar to that of Python's request repository ([Python] BS4 library).
-
Each new requests initializes a cache instance which stores the parsed data in key value pairs
-
When you get an instance of connect, you can call the parser method to parse the data in the form of closure
Example
let data = new;
let client = new;
let mut rq = client.connect;
rq.parser; //
data.print
Use data.print you can view the value stored as the [href] key. It is a value enumeration type that contains most data types.
- output
Key -- "href" Value -- LIST
Headers
Headers defines three types of request headers. The default Header::default has only one user agent, or it can be without any Headers::None.also use JSON string to make a request header containing useragent and host, this code:
let headers = r#"{"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36", "host": "www.qq.com"}"#;
let store = new;
let client = new;
let mut p = client.connect;
If you need more request header fields, you need to use add corresponding fields in headers.rs
Parser
When you use the connect method to connect to a URL, you can use the parser method to write the work of parsing HTML, the current parser has find and find_ all method
the parser must return Value type
If you use find find_all the code:
rq.parser
The first parameter of parser is obtained by closure automatically saves the value to value:: list
In general, you may need to handle the parsing manually and customize the returned Value, please use p.select function , this example code:
let data = new;
let client = new;
let mut parser = client.connect;
parser.parser;
data.print;
Value
Add the data type you need in the Value.rs
Concurrency support
use rayon library test the concurrency, this have a simple code:
let data = new;
let client = new;
let urls = ;
let _ = urls.par_iter.map
.map.;
match data.get ;
if let STR = data.get
if let STR = data.get