Rust 爬虫入门

要通过rust爬虫最好先学习一下tokio库,此外还需要工具库hyper(发送请求,得到数据),
html5ever(解析html),下面先上个例子,等有时间再发个实践的

extern crate hyper_tls;
extern crate html5ever;
extern crate hyper;
extern crate futures;

use hyper_tls::HttpsConnector;
use hyper::Client;
use hyper::rt::{self,Stream,Future};

use html5ever::rcdom::{RcDom,Handle};
use html5ever::tendril::StrTendril;
use html5ever::parse_document;
use html5ever::tendril::TendrilSink;
use html5ever::rcdom::NodeData;

use std::collections::HashSet;
use std::default::Default;
use std::sync::Arc;
use std::borrow::Borrow;
use std::clone::Clone;

use futures::future;

#[derive(Clone)]
struct FocusHref {
    ahref:HashSet<String>,
    imghref:HashSet<String>,
}
impl FocusHref {
    fn new(url:String) -> impl Future<Item = FocusHref,Error = ()> {
        let url:hyper::Uri = url.parse().unwrap();
        let https = HttpsConnector::new(4).unwrap();
        let client = Client::builder().build::<_,hy
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值