#search #google

search_with_google

A simple library to crawl the google search page

6 releases

✓ Uses Rust 2018 edition

new 0.3.1 Jul 2, 2020
0.3.0 Jul 1, 2020
0.2.2 Jun 30, 2020
0.1.0 Jun 28, 2020

#74 in #search

21 downloads per month

MIT and MPL-2.0 licenses

8KB
162 lines

search_with_google

A simple library that crawls the google search results page

Usage

NOTE:

If you're coming from V 0.2.x replace use search_with_google::search; with use search_with_google::blocking::search;

Insert this in Cargo.toml

[dependencies]
search_with_google = "0.3"

for regular non-async

use search_with_google::blocking::search;
let results = search("rust", 3, None);
if let Ok(result_list) = results {
    println!("Title : {}\nLink : {}", result_list[0].title, result_list[0].link);
}

for async

use search_with_google::search;
let results = search("rust", 3, None).await;
if let Ok(result_list) = results {
    println!("Title : {}\nLink : {}", result_list[0].title, result_list[0].link);
}

Here the second and third parameters are

  • limit: u32 -> maximum number of search results to retrieve (Default: 10)
  • agent: String -> the user agent to use (Default: "Mozilla/5.0 (X11; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0".to_string())

You can pass None to either to use the defaults

SearchResult is a struct with title, link and description.

pub struct SearchResult {
    pub link: String,
    pub title: String,
    pub description: String,
}

Changelog

0.1.0 -> 0.2.2

  • option is now limit
  • You can now specify a User Agent
  • You can directly pass Optional parameters like limit: u32, agent: String instead of Some(limit) etc.
  • SearchError is now Error

0.2.2 -> 0.3.1

  • async option available with use search_with_google::search;
  • blocking option available with use search_with_google::blocking::search;
  • Error properly implements std::error::Error

Credits

Based on google-somethin

Dependencies

~7–10MB
~220K SLoC