推荐学习书目
› 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
coolair
V2EX  ›  Python

BeautifulSoup 如何处理这种情况?

  •  
  •   coolair · Aug 8, 2014 · 3154 views
    This topic created in 4440 days ago, the information mentioned may be changed or developed.
    <div class="a">aaa1</div>
    <div class="b">bbb1</div>

    <div class="a">aaa2</div>

    <div class="a">aaa3</div>
    <div class="b">bbb3</div>

    <div class="a">aaa4</div>

    <div class="a">aaa5</div>
    <div class="b">bbb5</div>

    <div class="a">aaa6</div>
    抓出如下输出:
    aaa1
    bbb1
    ===
    aaa2
    ===
    aaa3
    bbb3
    ===
    aaa4
    ===
    aaa5
    bbb5
    ===
    aaa6

    谢谢!
    2 replies  •  2014-08-08 23:54:41 +08:00
    xunyu
        1
    xunyu  
       Aug 8, 2014
    findAll{'div'}
    4mrqn07k
        2
    4mrqn07k  
       Aug 8, 2014
    如同楼上所说,然后用 string or contents or get_text() 都可以
    这些在 bs4 的中文文档里面写的很清楚
    http://beautifulsoup.readthedocs.org/zh_CN/latest/

    只不过你的意思貌似还和分组排序有关系,这可能就要和父节点联系起来才有可能得到你想要的分组顺序
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2429 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:32 · PVG 21:32 · LAX 06:32 · JFK 09:32
    ♥ Do have faith in what you're doing.