1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-07 16:15:32 +02:00

fix has_single_tag_inside_element & update tests

This commit is contained in:
Jan Lukas Gernert 2023-02-28 03:59:48 +01:00
parent 31a8033844
commit aea57d0cf3
10 changed files with 86 additions and 39 deletions

View file

@ -1,4 +1,4 @@
<article><DIV id="readability-page-1" class="page"><section><p><strong>So finally you're <a href="/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">testing your frontend JavaScript code</a>? Great! The more you <article><section id="readability-page-1"><p><strong>So finally you're <a href="/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/" target="_blank">testing your frontend JavaScript code</a>? Great! The more you
write tests, the more confident you are with your code… but how much precisely? write tests, the more confident you are with your code… but how much precisely?
That's where <a href="http://en.wikipedia.org/wiki/Code_coverage" target="_blank">code coverage</a> might That's where <a href="http://en.wikipedia.org/wiki/Code_coverage" target="_blank">code coverage</a> might
help.</strong></p> help.</strong></p>
@ -117,4 +117,4 @@ describe("Cow", function() {
sessions sessions
and <a href="http://alexgaynor.net/2013/sep/26/effective-code-review/" target="_blank">code reviews</a> and <a href="http://alexgaynor.net/2013/sep/26/effective-code-review/" target="_blank">code reviews</a>
but that's another story.</p> but that's another story.</p>
<p><strong>So is code coverage silver bullet? No. Is it useful? Definitely. Happy testing!</strong></p></section></DIV></article> <p><strong>So is code coverage silver bullet? No. Is it useful? Definitely. Happy testing!</strong></p></section></article>

View file

@ -1,4 +1,4 @@
<article><DIV id="readability-page-1" class="page"><article role="article"><p>For more than a decade the Web has used XMLHttpRequest (XHR) to achieve <article><DIV id="readability-page-1"><article role="article"><p>For more than a decade the Web has used XMLHttpRequest (XHR) to achieve
asynchronous requests in JavaScript. While very useful, XHR is not a very asynchronous requests in JavaScript. While very useful, XHR is not a very
nice API. It suffers from lack of separation of concerns. The input, output nice API. It suffers from lack of separation of concerns. The input, output
and state are all managed by interacting with one object, and state is and state are all managed by interacting with one object, and state is

View file

@ -1,4 +1,4 @@
<article><DIV id="readability-page-1" class="page"><DIV><article><h2>Test document title</h2> <article><DIV id="readability-page-1"><article><h2>Test document title</h2>
<p> <p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
@ -14,4 +14,4 @@
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p></article></DIV></DIV></article> </p></article></DIV></article>

View file

@ -1,4 +1,4 @@
<article><DIV id="readability-page-1" class="page"><div> <article><div id="readability-page-1">
<p> <p>
I don't use Facebook. I'm not technophobic — I'm a geek. I've been using email since the early 1990s, I have accounts on hundreds of services around the net, and I do software development and internet protocol design both for work and for fun. I believe that a globe-spanning communications network like the internet can be a positive social force, and I publish much of my own work on the open web. I don't use Facebook. I'm not technophobic — I'm a geek. I've been using email since the early 1990s, I have accounts on hundreds of services around the net, and I do software development and internet protocol design both for work and for fun. I believe that a globe-spanning communications network like the internet can be a positive social force, and I publish much of my own work on the open web.
</p> </p>
@ -104,4 +104,4 @@
<p> <p>
As we work to address the fallout from the current storm around Facebook and Cambridge Analytica, we can't afford to lose sight of these larger mechanisms at play. Cambridge Analytica's failures and mistakes are inherent to Facebook's business model. We need to seriously challenge the social structures that encourage people to opt in to this kind of surveillance. At the same time, we also need to protect those of us who manage to opt out. As we work to address the fallout from the current storm around Facebook and Cambridge Analytica, we can't afford to lose sight of these larger mechanisms at play. Cambridge Analytica's failures and mistakes are inherent to Facebook's business model. We need to seriously challenge the social structures that encourage people to opt in to this kind of surveillance. At the same time, we also need to protect those of us who manage to opt out.
</p> </p>
</div></DIV></article> </div></article>

View file

@ -1 +1,68 @@
FIXME <article><DIV id="readability-page-1">
<p>
Zázrak jedné sezony? West Ham dává pochybovačům stále pádnější odpovědi a fotbalový svět si začíná uvědomovat, že se absolutní anglická fotbalová elita rozrůstá o nového člena. Tým manažera Davida Moyese prohání giganty i v aktuálním ročníku Premier League.
</p>
<div id="article-content">
<p>
Pět vítězných soutěžních duelů v řadě, během nich jediný inkasovaný gól. Čtvrté místo v lize, stejný bodový zisk jako loňský šampion Manchester City a nadšené ohlasy z tábora těch nejrenomovanějších komentátorů ostrovního fotbalu.
</p>
<p>
West Ham je opět v kurzu, nadšené ohlasy po nedělní jasné výhře 4:1 na hřišti Aston Villy zaplnily anglický mediální prostor.
</p>
<p>
"Stali se excelentním týmem. Jsou skvělí ve všech částech hřiště a David Moyes si zaslouží obrovský kredit za to, do jaké pozice je dostal," píše na Twitter Gary Lineker.
</p>
<p>
"Nenapadá mě jediný důvod, proč by letos nemohli skončit v elitní čtyřce," přidává se Emile Heskey, někdejší útočník Liverpoolu. "Je fér říct, že vypadají fantasticky. Moyes je neskutečně oživil."
</p>
<p>
I Heskey si všiml, že se Kladiváři skvěle vyrovnávají s náročným programem a pro ně novou rolí: účastí ve více soutěžích najednou. Moyes zůstává konzervativní v určování základní sestavy, chytře ale rozšířil kádr a v Evropské lize či ligovém poháru nechává některé opory odpočívat. Výjimkou potvrzující pravidlo je přitom Tomáš Souček, o jehož nezbytnosti bude řeč níže.
</p>
<p>
"Klíčová věc je ta, že když udělá změny, pořád jim zůstává stejná struktura. To je něco, co pravidelně říkáme třeba o Manchesteru City. Ve hře neustále zůstává nějaká fundamentální filosofie. West Ham to má podobně a už kvůli tomu je třeba před Moyesem smeknout," přirovnává Heskey.
</p>
<p><em>Podívejte se na důležité momenty zápasu Aston Villa - West Ham:</em></p>
<p>
V Evropské lize má West Ham po třech zápasech plný bodový zisk. V anglickém ligovém poháru dobyl čtvrtfinále, když vyřadil oba bohaté velkokluby z Manchesteru.
</p>
<p>
Čeští fotbalisté nicméně momentálně nejsou ve světlech těch nejjasnějších reflektorů.
</p>
<p>
Vladimír Coufal už sice uzdravil poraněné tříslo, v sestavě ale před ním dostal přednost rozjetý Ben Johnson. Anglický mladík další působivé představení okořenil parádním gólem a potvrdil, že se stává tvrdou konkurencí pro českého reprezentačního beka.
</p>
<p>
Tomáš Souček zůstává nepostradatelným členem základní sestavy, navzdory tomu, že jeho poslední výkony působí nenápadně.
</p>
<p>
"Pořád toho odvádí strašnou spoustu mimo hlavní pozornost. Jsou to důležité věci, které je snadné přehlédnout," píše ve svém hodnocení server Claret and Hugh. 
</p>
<p>
"S Declanem Ricem vytvořil silné partnerství a udělal spoustu těžké práce. Má dobrou rozehrávku. Jediné, na co si lze stěžovat, jsou jeho občasná špatná rozhodnutí ve finální třetině hřiště," hodnotí českého středopolaře londýnský večerník Evening Standard.
</p>
<p>
Web Football.London to vidí podobně. "Opět byl silný ve vzduchu, na obou koncích hřiště. Ve finální fázi se ale nerozhodoval dobře, příliš často volil špatnou variantu."
</p>
<p>
Moyes nicméně nenechává Součka oddechnout. V pěti posledních utkáních, které West Ham odehrál během pouhých čtrnácti dnů, chyběl Čech jen pár minut v závěru na Evertonu, když utrpěl zranění v obličeji.
</p>
<p>
Fanoušci pravidelně spekulují o únavě, skotský manažer ale - jak se zdá - bude mít v sestavě raději unaveného Součka než kohokoli jiného. Zvlášť, když Alex Král, plánovaný back-up do středu zálohy, stále není k dispozici.
</p>
<p>
Zatímco v minulé sezoně Souček častokrát zastínil svého kolegu Rice, letos je to právě anglický reprezentant, kdo si užívá zasloužené ódy na svou adresu.
</p>
<p>
"Hraje prostě velkolepě a připomínám, že je mu stále jen dvaadvacet let," kroutí hlavou Lineker. Není sám. Ještě před pár měsíci se většina odborníků pozastavovala nad údajnou cenovkou kolem 100 milionů liber. Nyní už zaznívají hlasy o tom, jak může být i tato hranice při případném přestupu Declana Rice výrazně překročena.
</p>
<p>
S blížícím se zimním přestupním termínem budou spekulace nabývat na síle, fanoušci Hammers ale věří, že Rice zůstane nejméně do léta. Jeho spokojenost je do očí bijící, stejně jako ochota nechat na hřišti všechno ve prospěch Clarets and Blues.
</p>
<p>
"Náš kolektiv je teď opravdu speciální. Působíme ve výjimečném prostředí. Každé ráno se probouzíme s obrovskou touhou po dalším tréninku. Jsme nadšení," tvrdí mladá anglická superstar.
</p>
<p>
"Jsme na děleném třetím místě. Lidé se před sezonou hodně ptali, zda to můžeme dokázat znovu. Ukázali jsme, že ano. Ale musíme pokračovat. Tohle musí být náš standard. Nesmíme polevit, pokud chceme být velkým týmem," zdůrazňuje Rice.
</p>
</div>
</DIV></article>

View file

@ -1,4 +1,4 @@
<article><DIV id="readability-page-1" class="page"><div id="textArea"> <article><div id="readability-page-1">
<p>Feb. 23, 2015 -- Life-threatening peanut allergies have mysteriously <p>Feb. 23, 2015 -- Life-threatening peanut allergies have mysteriously
been been
on the rise in the past decade, with little hope for a cure.</p> on the rise in the past decade, with little hope for a cure.</p>
@ -59,4 +59,4 @@
to peanuts and other tree nuts can be especially severe. Nuts are to peanuts and other tree nuts can be especially severe. Nuts are
the main the main
reason people get a life-threatening problem called <a href="http://www.webmd.com/allergies/guide/anaphylaxis" target="_blank">anaphylaxis</a>.</p> reason people get a life-threatening problem called <a href="http://www.webmd.com/allergies/guide/anaphylaxis" target="_blank">anaphylaxis</a>.</p>
</div></DIV></article> </div></article>

View file

@ -900,18 +900,10 @@ impl FullTextParser {
let mut node_iter = Some(root.clone()); let mut node_iter = Some(root.clone());
while let Some(mut node) = node_iter { while let Some(mut node) = node_iter {
let classes = node.get_class_names(); node.remove_attribute("class").map_err(|e| {
if classes.contains("page") { log::error!("{e}");
node.set_attribute("class", "page").map_err(|e| { FullTextParserError::Xml
log::error!("{e}"); })?;
FullTextParserError::Xml
})?;
} else {
node.remove_attribute("class").map_err(|e| {
log::error!("{e}");
FullTextParserError::Xml
})?;
}
node.remove_attribute(constants::SCORE_ATTR).map_err(|e| { node.remove_attribute(constants::SCORE_ATTR).map_err(|e| {
log::error!("{e}"); log::error!("{e}");

View file

@ -399,8 +399,8 @@ impl Readability {
for mut sibling in siblings { for mut sibling in siblings {
let mut append = false; let mut append = false;
let score = Self::get_content_score(&sibling); let score = Self::get_content_score(&sibling).unwrap_or(0.0);
log::debug!("Looking at sibling node: {sibling:?} with score {score:?}"); log::debug!("Looking at sibling node: {sibling:?} with score {score}");
if top_candidate == sibling { if top_candidate == sibling {
append = true; append = true;
@ -420,9 +420,7 @@ impl Readability {
Self::get_content_score(&top_candidate).unwrap_or(0.0) * 0.2; Self::get_content_score(&top_candidate).unwrap_or(0.0) * 0.2;
} }
if Self::get_content_score(&sibling).unwrap_or(0.0) + content_bonus if score + content_bonus >= sibling_score_threshold {
>= sibling_score_threshold
{
append = true; append = true;
} else if sibling.get_name().to_uppercase() == "P" { } else if sibling.get_name().to_uppercase() == "P" {
let link_density = Util::get_link_density(&sibling); let link_density = Util::get_link_density(&sibling);
@ -476,12 +474,6 @@ impl Readability {
log::error!("{error}"); log::error!("{error}");
FullTextParserError::Readability FullTextParserError::Readability
})?; })?;
top_candidate
.set_property("class", "page")
.map_err(|error| {
log::error!("{error}");
FullTextParserError::Readability
})?;
} else { } else {
let mut div = Node::new("DIV", None, &document) let mut div = Node::new("DIV", None, &document)
.map_err(|()| FullTextParserError::Readability)?; .map_err(|()| FullTextParserError::Readability)?;
@ -490,10 +482,6 @@ impl Readability {
log::error!("{error}"); log::error!("{error}");
FullTextParserError::Readability FullTextParserError::Readability
})?; })?;
div.set_property("class", "page").map_err(|error| {
log::error!("{error}");
FullTextParserError::Readability
})?;
for mut child in article_content.get_child_nodes() { for mut child in article_content.get_child_nodes() {
child.unlink(); child.unlink();

View file

@ -40,7 +40,7 @@ async fn run_test(name: &str) {
article.document = Some(article_document); article.document = Some(article_document);
let html = article.get_content().unwrap(); let html = article.get_content().unwrap();
std::fs::write("expected.html", &html).unwrap(); //std::fs::write("expected.html", &html).unwrap();
let expected = std::fs::read_to_string(format!( let expected = std::fs::read_to_string(format!(
"./resources/tests/readability/{name}/expected.html" "./resources/tests/readability/{name}/expected.html"

View file

@ -380,7 +380,7 @@ impl Util {
} }
// And there should be no text nodes with real content // And there should be no text nodes with real content
node.get_child_nodes().iter().any(|n| { !node.get_child_nodes().iter().any(|n| {
n.get_type() n.get_type()
.map(|t| t == NodeType::TextNode) .map(|t| t == NodeType::TextNode)
.unwrap_or(false) .unwrap_or(false)