The Article extraction lifecycle: download, parse, and nlp
masterTo extract data from an Article, you must follow a specific sequence of method calls:
download(): Fetches the HTML. A freshly initialized article has no content until this is called. This method can be run in a multi-threaded fashion.parse(): Extracts meaningful text, title, authors, images, etc., from the downloaded HTML. Note: Callingparse()beforedownload()will raise anArticleException.nlp(): Performs Natural Language Processing to populatesummaryandkeywords. This is computationally expensive and should be used sparingly. Note: You must call bothdownload()andparse()before callingnlp(). Currently,nlp()only works on western languages.
Available properties after parse():
text: The main article text.title: The article title.authors: A list of authors.top_image: The primary image URL.images: A list of all image URLs.movies: A list of video URLs (YouTube, Vimeo, etc.).
# The standard workflow
article = newspaper.article(url='http://example.com/article')
article.download()
article.parse()
print(article.text)
print(article.title)
# Optional NLP step
article.nlp()
print(article.summary)
print(article.keywords)