added redirecting to light novels

This commit is contained in:
Zastian Pretorius
2022-10-30 01:07:20 +00:00
parent 52dab31fe3
commit ca8c8c12e8

View File

@@ -1,3 +1,4 @@
use isahc::config::Configurable;
use isahc::{ReadResponseExt, Request, RequestExt}; use isahc::{ReadResponseExt, Request, RequestExt};
use regex::Regex; use regex::Regex;
@@ -9,18 +10,17 @@ use crate::helpers::fixing_text::fix_html_encoding;
pub fn get_html(url: &str) -> String { pub fn get_html(url: &str) -> String {
let req = Request::builder() let req = Request::builder()
.uri(url) .uri(url)
.header( .redirect_policy(isahc::config::RedirectPolicy::Follow)
"user-agent", .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36")
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
)
.body(()) .body(())
.unwrap(); .unwrap();
let mut res = req.send().unwrap();
req.send().unwrap().text().unwrap() let html = res.text().unwrap();
html
} }
//using isahc::prelude::* make a php reqest to get the next page of the ln //using isahc::prelude::* make a php reqest to get the next page of the ln
pub fn get_ln_next_page(ln_id: &str, page: &str) -> String { pub fn get_ln_next_page(ln_id: &str, page: &u32) -> String {
let url = "https://readlightnovels.net/wp-admin/admin-ajax.php".to_string(); let url = "https://readlightnovels.net/wp-admin/admin-ajax.php".to_string();
let form = format!( let form = format!(
"action=tw_ajax&type=pagination&id={}.html&page={}", "action=tw_ajax&type=pagination&id={}.html&page={}",
@@ -30,14 +30,15 @@ pub fn get_ln_next_page(ln_id: &str, page: &str) -> String {
let req = Request::builder() let req = Request::builder()
.method("POST") .method("POST")
.uri(url) .uri(url)
.redirect_policy(isahc::config::RedirectPolicy::Follow)
.header( .header(
"user-agent", "user-agent",
"Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0", "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/100.0",
) )
.body(form) .body(form)
.unwrap(); .unwrap();
let resp = req.send().unwrap().text().unwrap();
req.send().unwrap().text().unwrap() resp
} }
pub fn get_full_text(chapter_url: &str) -> String { pub fn get_full_text(chapter_url: &str) -> String {