#web-scraping #flows #networking #page #text #flow #content

web-scraper-flows

Web scraper integration for flows.network

1 unstable release

0.1.0 Jun 9, 2023

#27 in #flows

Download history 26/week @ 2024-01-06 7/week @ 2024-01-13 1/week @ 2024-01-20 3/week @ 2024-02-17 17/week @ 2024-02-24 12/week @ 2024-03-02 18/week @ 2024-03-09 14/week @ 2024-03-16 23/week @ 2024-03-30 3/week @ 2024-04-06 29/week @ 2024-04-20

55 downloads per month

MIT/Apache

7KB
57 lines

This is a library for integrating Web Scraper in your flow function for flows.network.

Visit Web Scraper

Below examples show a lambda service that responds with the text content of a web page for a url passed as query parameter.

use std::collections::HashMap;

use lambda_flows::{request_received, send_response};
use serde_json::Value;
use web_scraper_flows::get_page_text;

#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn run() {
    request_received(handler).await;
}

async fn handler(qry: HashMap<String, Value>, _body: Vec<u8>) {
    let url = qry.get("url").expect("No url provided").as_str().unwrap();

    match get_page_text(url).await {
        Ok(text) => send_response(
            200,
            vec![(
                String::from("content-type"),
                String::from("text/plain; charset=UTF-8"),
            )],
            text.as_bytes().to_vec(),
        ),
        Err(e) => send_response(
            400,
            vec![(
                String::from("content-type"),
                String::from("text/plain; charset=UTF-8"),
            )],
            e.as_bytes().to_vec(),
        ),
    }
}

The whole document is here.

Dependencies

~435KB