GeezerVison is showing github.com — Release version 0.7 . Better HTML5 support and an important bugfix. · elcsong/python-readability@0e50b53
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .travis.yml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 |
| 12 | 12 | before_install: | 13 | 13 | # work around https://github.com/travis-ci/travis-ci/issues/8363 | 14 | | - - pyenv global system 3.5 | | 14 | + - pyenv global system 3.6 | 15 | 15 |
| 16 | 16 | install: | 17 | 17 | - travis_retry pip install -U pip wheel tox | |
Collapse file Copy file name to clipboardExpand all lines: Makefile +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | # Makefile to help automate tasks | 2 | 2 | WD := $(shell pwd) | 3 | | -PY := .env/bin/python | 4 | | -PIP := .env/bin/pip | 5 | | -PEP8 := .env/bin/pep8 | 6 | | -NOSE := .env/bin/nosetests | 7 | | - | | 3 | +PY := .venv/bin/python | | 4 | +PIP := .venv/bin/pip | | 5 | +PEP8 := .venv/bin/pep8 | | 6 | +NOSE := .venv/bin/nosetests | 8 | 7 |
| 9 | 8 | # ########### | 10 | 9 | # Tests rule! | @@ -22,16 +21,17 @@ $(NOSE): | 22 | 21 | .PHONY: all | 23 | 22 | all: venv develop | 24 | 23 |
| 25 | | -venv: bin/python | 26 | | -bin/python: | 27 | | - virtualenv .env | | 24 | +venv: .venv/bin/python | | 25 | + | | 26 | +.venv/bin/python: | | 27 | + virtualenv .venv | 28 | 28 |
| 29 | 29 | .PHONY: clean_venv | 30 | 30 | clean_venv: | 31 | | - rm -rf .env | | 31 | + rm -rf .venv | 32 | 32 |
| 33 | | -develop: .env/lib/python*/site-packages/readability-lxml.egg-link | 34 | | -.env/lib/python*/site-packages/readability-lxml.egg-link: | | 33 | +develop: .venv/lib/python*/site-packages/readability-lxml.egg-link | | 34 | +.venv/lib/python*/site-packages/readability-lxml.egg-link: | 35 | 35 | $(PY) setup.py develop | 36 | 36 |
| 37 | 37 |
| |
Collapse file Copy file name to clipboardExpand all lines: README.rst +7-5Lines changed: 7 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -35,13 +35,15 @@ Usage | 35 | 35 | Change Log | 36 | 36 | ---------- | 37 | 37 |
| 38 | | -- 0.3 Added Document.encoding, positive\_keywords and | 39 | | - negative\_keywords | 40 | | -- 0.4 Added Videos loading and allowed more images per paragraph | 41 | | -- 0.5 Preparing a release to support Python versions 2.6, 2.7, 3.3 and | 42 | | - 3.4 | | 38 | +- 0.7 Improved HTML5 tags handling. Heuristics were changed for a lot of sites: Fixed an important | | 39 | +bug with stripping unwanted HTML nodes (only first matching node was removed before). | 43 | 40 | - 0.6 Finally a release which supports Python versions 2.6, 2.7, 3.3 | 44 | 41 | and 3.4 | | 42 | +- 0.5 Preparing a release to support Python versions 2.6, 2.7, 3.3 and | | 43 | + 3.4 | | 44 | +- 0.4 Added Videos loading and allowed more images per paragraph | | 45 | +- 0.3 Added Document.encoding, positive\_keywords and | | 46 | + negative\_keywords | 45 | 47 |
| 46 | 48 | Licensing | 47 | 49 | ========= | |
Collapse file Copy file name to clipboardExpand all lines: readability/readability.py +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -381,13 +381,13 @@ def class_weight(self, e): | 381 | 381 | def score_node(self, elem): | 382 | 382 | content_score = self.class_weight(elem) | 383 | 383 | name = elem.tag.lower() | 384 | | - if name == "div": | | 384 | + if name in ["div", "article"]: | 385 | 385 | content_score += 5 | 386 | 386 | elif name in ["pre", "td", "blockquote"]: | 387 | 387 | content_score += 3 | 388 | | - elif name in ["address", "ol", "ul", "dl", "dd", "dt", "li", "form"]: | | 388 | + elif name in ["address", "ol", "ul", "dl", "dd", "dt", "li", "form", "aside"]: | 389 | 389 | content_score -= 3 | 390 | | - elif name in ["h1", "h2", "h3", "h4", "h5", "h6", "th"]: | | 390 | + elif name in ["h1", "h2", "h3", "h4", "h5", "h6", "th", "header", "footer", "nav"]: | 391 | 391 | content_score -= 5 | 392 | 392 | return { | 393 | 393 | 'content_score': content_score, | @@ -463,7 +463,7 @@ def sanitize(self, node, candidates): | 463 | 463 |
| 464 | 464 | allowed = {} | 465 | 465 | # Conditionally clean <table>s, <ul>s, and <div>s | 466 | | - for el in self.reverse_tags(node, "table", "ul", "div"): | | 466 | + for el in self.reverse_tags(node, "table", "ul", "div", "aside", "header", "footer", "section"): | 467 | 467 | if el in allowed: | 468 | 468 | continue | 469 | 469 | weight = self.class_weight(el) | @@ -577,7 +577,7 @@ def sanitize(self, node, candidates): | 577 | 577 | if siblings and sum(siblings) > 1000: | 578 | 578 | to_remove = False | 579 | 579 | log.debug("Allowing %s" % describe(el)) | 580 | | - for desnode in self.tags(el, "table", "ul", "div"): | | 580 | + for desnode in self.tags(el, "table", "ul", "div", "section"): | 581 | 581 | allowed[desnode] = True | 582 | 582 |
| 583 | 583 | if to_remove: | |
Collapse file Copy file name to clipboardExpand all lines: setup.py +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 14 | 14 |
| 15 | 15 | setup( | 16 | 16 | name="readability-lxml", | 17 | | - version="0.6.2", | | 17 | + version="0.7", | 18 | 18 | author="Yuri Baburov", | 19 | 19 | | 20 | 20 | description="fast html to text parser (article readability tool) with python3 support", | | 43 | 43 | "Programming Language :: Python :: 3.4", | 44 | 44 | "Programming Language :: Python :: 3.5", | 45 | 45 | "Programming Language :: Python :: 3.6", | 46 | | - | 47 | 46 | ], | 48 | 47 | ) |
Collapse file Copy file name to clipboardExpand all lines: tests/test_article_only.py +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,3 +61,34 @@ def test_best_elem_is_root_and_passing(self): | 61 | 61 | ) | 62 | 62 | doc = Document(sample) | 63 | 63 | doc.summary() | | 64 | + | | 65 | + def test_correct_cleanup(self): | | 66 | + sample = """ | | 67 | + <html> | | 68 | + <body> | | 69 | + <section>test section</section> | | 70 | + <article class=""> | | 71 | +<p>Lot of text here.</p> | | 72 | + <div id="advertisement"><a href="link">Ad</a></div> | | 73 | +<p>More text is written here, and contains punctuation and dots.</p> | | 74 | +</article> | | 75 | + <aside id="comment1"/> | | 76 | + <div id="comment2"> | | 77 | + <a href="asd">spam</a> | | 78 | + <a href="asd">spam</a> | | 79 | + <a href="asd">spam</a> | | 80 | + </div> | | 81 | + <div id="comment3"/> | | 82 | + <aside id="comment4">A small comment.</aside> | | 83 | + <div id="comment5"><p>The comment is also helpful, but it's | | 84 | + still not the correct item to be extracted.</p> | | 85 | + <p>It's even longer than the article itself!"</p></div> | | 86 | + </body> | | 87 | + </html> | | 88 | + """ | | 89 | + doc = Document(sample) | | 90 | + s = doc.summary() | | 91 | + #print(s) | | 92 | + assert('punctuation' in s) | | 93 | + assert(not 'comment' in s) | | 94 | + assert(not 'aside' in s) |
|