Skip to content

Commit acd378f

Browse files
authored
Merge pull request #618 from flairNLP/fix-the-namibian
Remove `<br>` tags in html
2 parents f255604 + 701556b commit acd378f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/fundus/publishers/na/the_namibian.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
from datetime import datetime
33
from typing import List, Optional, Pattern
44

5+
import lxml.html
56
from lxml.etree import XPath
67

7-
from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute
8+
from fundus.parser import ArticleBody, BaseParser, ParserProxy, attribute, function
9+
from fundus.parser.base_parser import Precomputed
810
from fundus.parser.utility import (
911
extract_article_body_with_selector,
1012
generic_author_parsing,
1113
generic_date_parsing,
14+
get_ld_content,
15+
get_meta_content,
1216
)
1317

1418

@@ -44,5 +48,15 @@ def authors(self) -> List[str]:
4448

4549
class V1_1(V1):
4650
VALID_UNTIL = datetime.today().date()
47-
_paragraph_selector = XPath("//div[contains(@class, 'entry-content')]/p[position()>1]")
48-
_summary_selector = XPath("//div[contains(@class, 'entry-content')]/p[position()=1]")
51+
_paragraph_selector = XPath("//div[contains(@class, 'entry-content')]/p[(text() or strong) and position()>1]")
52+
_summary_selector = XPath("//div[contains(@class, 'entry-content')]/p[(text() or strong) and position()=1]")
53+
54+
@attribute
55+
def body(self) -> ArticleBody:
56+
html = re.sub(r"(<br>)+", "<p>", self.precomputed.html)
57+
doc = lxml.html.document_fromstring(html)
58+
return extract_article_body_with_selector(
59+
doc,
60+
paragraph_selector=self._paragraph_selector,
61+
summary_selector=self._summary_selector,
62+
)

tests/resources/parser/test_data/na/TheNamibian.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
"He said he, Mbumba and Geingob planned to settle at Swakopmund and to sometimes walk barefoot by the seaside and have coffee at a nearby café.",
8787
"GOING HOME TO DIE",
8888
"Political analyst Henning Melber questions the circumstances surrounding Geingob’s departure, suggesting that if an inner circle was aware of his imminent passing, his trip to the US wouldn’t have been for medical treatment.",
89-
"Melber speculates that Geingob may have realised his life was ending during his time in the US and chose to return home to die.However, Melber questions why this should be a contentious issue.",
89+
"Melber speculates that Geingob may have realised his life was ending during his time in the US and chose to return home to die.",
90+
"However, Melber questions why this should be a contentious issue.",
9091
"“This means that as of his arrival back in Namibia people may have become aware that not much time was left. But why make an issue of it?",
9192
"“If one could provide evidence that it was exploited for dubious arrangements, it would be another matter. But I do not see any indications pointing reliably into such a direction,” he says."
9293
]

0 commit comments

Comments
 (0)