Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve issue #70: return full text article #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions gnews/gnews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down