推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ten
V2EX  ›  Python

用 BeautifulSoup,如何过滤某些标签 比如我想对 “ </p>, <p data-page-model="text"> ”这个进行过滤

  •  
  •   ten · Jan 5, 2017 · 3392 views
    This topic created in 3422 days ago, the information mentioned may be changed or developed.
    2 replies    2017-01-06 22:16:04 +08:00
    JohnDHH
        1
    JohnDHH  
       Jan 6, 2017
    In [1]: from bs4 import BeautifulSoup

    In [2]: soup = BeautifulSoup('''<p data-page-model="text">a</p>\n <p data-page="text">b</p>''', "html.parser")

    In [3]: soup.find_all("p", attrs={'data-page-model':'text'})
    Out[3]: [<p data-page-model="text">a</p>]

    In [4]: soup.find_all("p", attrs={'data-page':'text'})
    Out[4]: [<p data-page="text">b</p>]
    mymusise
        2
    mymusise  
       Jan 6, 2017
    提前把 html document replace 一下?
    html.replace('</p>, <p data-page-model="text">','')
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5352 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 06:05 · PVG 14:05 · LAX 23:05 · JFK 02:05
    ♥ Do have faith in what you're doing.