Skip to content

kanjirz50/python-extractcontent3

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExtractContent3

image

image

image

image

ExtractContent3はPython3で動作する、HTMLから本文を抽出するモジュールです。 このモジュールは、ExtractContent RubyモジュールをPython用に書き直したpython-extracontentを改造したものです。

Usage

from extractcontent3 import ExtractContent
extractor = ExtractContent()

# オプション値を指定する
opt = {"threshold":50}
extractor.set_option(opt)

html = open("index.html").read() # 解析対象HTML
extractor.analyse(html)
text, title = extractor.as_text()
html, title = extractor.as_html()
title = extractor.extract_title(html)

Installation

# pypi
$ pip install extractcontent3

# Githubからのインストール
$ pip install git+https://github.com/kanjirz50/python-extractcontent3

Option

"""
オプションの種類:
名称 / デフォルト値

threshold / 100
本文と見なすスコアの閾値

min_length / 80
評価を行うブロック長の最小値

decay_factor / 0.73
減衰係数
小さいほど先頭に近いブロックのスコアが高くなります

continuous_factor / 1.62
連続ブロック係数
大きいほどブロックを連続と判定しにくくなる

punctuation_weight / 10
句読点に対するスコア 
大きいほど句読点が存在するブロックを本文と判定しやすくなる

punctuations r"(?is)([\u3001\u3002\uff01\uff0c\uff0e\uff1f]|\.[^A-Za-z0-9]|,[^0-9]|!|\?)"    
句読点を抽出する正規表現

waste_expressions / r"(?i)Copyright|All Rights Reserved"
フッターに含まれる特徴的なキーワードを指定した正規表現

debug / False
 Trueの場合、ブロック情報を出力
"""

謝辞

オリジナル版の作成者やForkで改良を加えた方々に感謝します。

About

HTMLから本文抽出を行うextractcontent.rb の Python3版

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 87.2%
  • Python 12.8%