天天看點

newspaper爬取新聞網站

newspaper爬取新聞網站

安裝newspaper

pip install newspaper3k
           

代碼

from newspaper import Article

url = '你想要爬取的網站url'
news = Article(url, language='zh')

news.download()  # 先下載下傳
news.parse()    # 再解析

text = news.text # 新聞正文
title = news.title # 新聞标題
html = news.html   # 未修改的原始HTML
authors = news.authors  # 新聞作者
top_image = news.top_image # 本文的“最佳圖像”的URL
movies = news.movies  # 本文電影url
keywords = news.keywords # 新聞關鍵詞
summary = news.summary   # 從文章主體txt中生成的摘要
images = news.images # 本文中的所有圖像url