scrapr_bindings/
protocols.rs1use crate::request::*;
2use pyo3::prelude::*;
3
4#[pyfunction]
5pub fn fetch_http(host: &str, path: &str) -> PyResult<String> {
6 scrapr_core::fetch_http(host, path)
7 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
8}
9
10#[pyfunction]
11pub fn fetch_http_with_options(
12 host: &str,
13 path: &str,
14 options: RequestOptions,
15) -> PyResult<String> {
16 let core_options = scrapr_core::RequestOptions {
17 headers: options.headers,
18 cookies: options.cookies,
19 query: options.query,
20 };
21
22 scrapr_core::fetch_http_with_options(host, path, core_options)
23 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
24}
25
26#[pyfunction]
27pub fn extract_attribute(text: &str, tag: &str, attr: &str) -> PyResult<Vec<String>> {
28 scrapr_core::extract_attribute(text, tag, attr)
29 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
30}
31
32#[pyfunction]
33pub fn extract_links(text: &str) -> PyResult<Vec<String>> {
34 extract_attribute(text, "a", "href")
35}
36
37#[pyfunction]
69pub fn extract_tag(text: &str, tag: &str) -> PyResult<Vec<String>> {
70 scrapr_core::extract_tag(text, tag)
71 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
72}
73
74#[pyfunction]
75pub fn fetch_https(host: &str, path: &str) -> PyResult<String> {
76 scrapr_core::fetch_https(host, path)
77 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
78}
79
80#[pyfunction]
81pub fn fetch_https_with_options(
82 host: &str,
83 path: &str,
84 options: RequestOptions,
85) -> PyResult<String> {
86 let core_options = scrapr_core::RequestOptions {
87 headers: options.headers,
88 cookies: options.cookies,
89 query: options.query,
90 };
91
92 scrapr_core::fetch_https_with_options(host, path, core_options)
93 .map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
94}