V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
coolloves
V2EX  ›  Python

请教个 html 解析的问题

  •  
  •   coolloves · 2021-03-27 14:25:20 +08:00 · 890 次点击
    这是一个创建于 1097 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近写了个脚本抓电视节目自用,遇到了个小问题,请教下,对于一个标签内,我怎么判断 a 标签的内容是在前还是后啊?
    如下情况,第一种 a 标签在后面呢,第二种情况,a 标签的内容就在前面,我目前是获取./span/text() + ./span/a/@href ,有些就是反的....
    <span class="p_show">海豚万家剧场:<a title="康熙王朝剧情介绍 " href="/drama/MnJXVQ==">康熙王朝</a></span>
    <span class="p_show"><a title="宇宙护卫队剧情介绍 " href="/drama/JFxhX2Nv">宇宙护卫队</a>2:爱探险的小梅花鹿</span>
    tia
        1
    tia  
       2021-03-27 14:31:02 +08:00
    试试 beautifulsoup
    coolloves
        2
    coolloves  
    OP
       2021-03-27 14:44:10 +08:00 via Android
    和 lxml 原理不一样吗?
    bs 怎么判断前后呢?请教
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   998 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 581ms · UTC 20:04 · PVG 04:04 · LAX 13:04 · JFK 16:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.