use crate::request::*;
use pyo3::prelude::*;
#[pyfunction]
pub fn fetch_http(host: &str, path: &str) -> PyResult<String> {
scrapr_core::fetch_http(host, path)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pyfunction]
pub fn fetch_http_with_options(
host: &str,
path: &str,
options: RequestOptions,
) -> PyResult<String> {
let core_options = scrapr_core::RequestOptions {
headers: options.headers,
cookies: options.cookies,
query: options.query,
};
scrapr_core::fetch_http_with_options(host, path, core_options)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pyfunction]
pub fn extract_attribute(text: &str, tag: &str, attr: &str) -> PyResult<Vec<String>> {
scrapr_core::extract_attribute(text, tag, attr)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pyfunction]
pub fn extract_links(text: &str) -> PyResult<Vec<String>> {
extract_attribute(text, "a", "href")
}
#[pyfunction]
pub fn extract_tag(text: &str, tag: &str) -> PyResult<Vec<String>> {
scrapr_core::extract_tag(text, tag)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pyfunction]
pub fn fetch_https(host: &str, path: &str) -> PyResult<String> {
scrapr_core::fetch_https(host, path)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}
#[pyfunction]
pub fn fetch_https_with_options(
host: &str,
path: &str,
options: RequestOptions,
) -> PyResult<String> {
let core_options = scrapr_core::RequestOptions {
headers: options.headers,
cookies: options.cookies,
query: options.query,
};
scrapr_core::fetch_https_with_options(host, path, core_options)
.map_err(|e| PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(e.to_string()))
}