Skip to content

Commit

Permalink
cleaned code
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayahhhmed committed Jan 6, 2024
1 parent 3aa3cbb commit b36bc87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
19 changes: 8 additions & 11 deletions src/scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,16 @@ pub trait Scraper {
fn new() -> Self;
fn set_url(&mut self, url: String) -> Self;
fn add_page(&mut self, page: Box::<dyn Page>);

async fn run_scraper_on_url(&mut self) -> Result<(), Box<dyn std::error::Error>>;

async fn fetch_url(&self, url: &str) -> Result<String, Box<dyn std::error::Error>> {
let client = ClientBuilder::new()
.danger_accept_invalid_certs(true)
.build()?;
let response = client.get(url).send().await?;
let body = response.text().await?;
Ok(body)
}
}

pub async fn fetch_url(url: &str) -> Result<String, Box<dyn std::error::Error>> {
let client = ClientBuilder::new()
.danger_accept_invalid_certs(true)
.build()?;
let response = client.get(url).send().await?;
let body = response.text().await?;
Ok(body)
}
// impl Scraper {


Expand Down
12 changes: 6 additions & 6 deletions src/subject_area_scraper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use scraper::Selector;

use crate::{
scraper::{Course, Page},
scraper::{Course, Page, fetch_url},
text_manipulators::{extract_text, get_html_link_to_page},
Scraper, UrlInvalidError,
};
Expand Down Expand Up @@ -37,12 +37,11 @@ impl std::fmt::Debug for dyn Page {
}
}


impl Scraper for SubjectAreaScraper {
async fn run_scraper_on_url(&mut self) -> Result<(), Box<dyn std::error::Error>> {
impl SubjectAreaScraper {
pub async fn run_scraper_on_url(&mut self) -> Result<(), Box<dyn std::error::Error>> {
match &self.url {
Some(url) => {
let html = self.fetch_url(url).await?;
let html = fetch_url(url).await?;
println!("{}", html);
let row_selector = Selector::parse("tr.rowLowlight, tr.rowHighlight").unwrap();
let code_selector = Selector::parse("td.data").unwrap();
Expand Down Expand Up @@ -81,7 +80,8 @@ impl Scraper for SubjectAreaScraper {
None => Err(Box::new(UrlInvalidError)),
}
}

}
impl Scraper for SubjectAreaScraper {
fn new() -> Self {
SubjectAreaScraper {
url: None,
Expand Down

0 comments on commit b36bc87

Please sign in to comment.