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
omg21
V2EX  ›  Python

soup 对象怎么判断有没有内容?

  •  
  •   omg21 · 2016-07-11 21:45:23 +08:00 · 1750 次点击
    这是一个创建于 2848 天前的主题,其中的信息可能已经有所发展或是发生改变。
    soup = BeautifulSoup(html,'lxml')
    我用 lxml 经常会有不能解析的网页(而且不能解析的时候什么显示都没有),必须用 html.parser 才行, lxml 效率高,不能不用。
    我现在想做个判断,如果 lxml 不能解析就用 html.parser ,
    可是这个 soup 应该怎么判断?不能解析的时候 soup 即不是 None ,也不是""
    1 条回复    2016-07-12 10:35:15 +08:00
    practicer
        1
    practicer  
       2016-07-12 10:35:15 +08:00
    bs 解析返回空值的原因有很多,不提供详细信息不好找原因,最好把目标网址发上来才好分析
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2872 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:51 · PVG 22:51 · LAX 07:51 · JFK 10:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.