To tear down news webpages in Taiwan.
Project description
台灣新聞拆拆樂 (twnews) 用來分解台灣各大新聞網站,取出重要的純文字內容
功能特色
支援蘋果日報、中央社、東森新聞雲、自由時報、三立新聞網、聯合新聞網
使用行動版網頁與快取機制節省流量
利用 BeautifulSoup 的 CSS selector 功能搭配設定檔分解,利於跟進網站改版
安裝
pip3 install twnews
範例
from twnews.soup import NewsSoup
nsoup = NewsSoup('https://tw.news.appledaily.com/local/realtime/20181025/1453825')
print('頻道: {}'.format(nsoup.channel))
print('標題: {}'.format(nsoup.title()))
print('日期: {}'.format(nsoup.date().isoformat()))
print('記者: {}'.format(nsoup.author()))
print('內文:')
print(nsoup.contents())
卡關了
如果新聞無法正確分解可能是網站改版了,利用 green 跑一下單元測試看看 假如單元測試失敗了,表示需要更新套件囉
pip3 install green # 安裝 green 套件
green -vvv twnews.tests # 使用 green 套件跑單元測試
pip3 install -U twnews # 更新 twnews
參考手冊
class twnews.soup.NewsSoup
NewsSoup.__init__(path, refresh=False, mobile=True)
建立新聞分解器
- path
本機檔案路徑或是網址
- refresh
使用網址時,是否要重新整理而不使用既有快取
- mobile
是否使用行動版網頁
NewsSoup.title()
取得新聞標題
NewsSoup.date()
取得發佈日期
NewsSoup.contents()
取得新聞內文
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
twnews-0.1.6-py3-none-any.whl
(193.2 kB
view hashes)