From 5e8875c77a987cf9b44cd44954af3a2158d15ad1 Mon Sep 17 00:00:00 2001 From: parth-lth Date: Mon, 10 Jun 2024 23:15:28 +0530 Subject: [PATCH] Solve issue #70: return full text article --- gnews/gnews.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gnews/gnews.py b/gnews/gnews.py index 62d5dc1..ca92c2e 100644 --- a/gnews/gnews.py +++ b/gnews/gnews.py @@ -169,9 +169,9 @@ def country(self, country): def get_full_article(self, url): """ - Download an article from the specified URL, parse it, and return an article object. + Download an article from the specified URL, parse it, and return the full text of the article. :param url: The URL of the article you wish to summarize. - :return: An `Article` object returned by the `newspaper3k` library if installed; otherwise, None. + :return: The full text of the article. """ try: import newspaper @@ -188,7 +188,12 @@ def get_full_article(self, url): print(f"An error occurred while fetching the article: {error}") return None - return article + if len(article.text) < 200: # Assuming that a complete article would have more than 200 characters + soup = Soup(article.html, 'html.parser') + full_text = soup.get_text() + return full_text.strip() + + return article.text.strip() @staticmethod