Use news-please as a Python library
masterYou can use news-please within your own Python code to extract semi-structured information from news articles. Note that Library mode is for extracting information from specific URLs or HTML; for full website crawling (starting from a root URL) or continuous RSS crawling, use the CLI mode.
Extracted attributes include: headline, lead paragraph, main text, main image, name(s) of author(s), publication date, and language.
from newsplease import NewsPlease
# Extract from a single URL
article = NewsPlease.from_url('https://www.nytimes.com/2017/02/23/us/politics/cpac-stephen-bannon-reince-priebus.html?hp')
print(article.title)
# Export to JSON
import json
with open("article.json", "w") as file:
json.dump(article.get_serializable_dict(), file)