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

BeautifulSoup 运行错误,求大神解答

  •  
  •   csy123 · 2016-08-25 19:44:19 +08:00 · 2666 次点击
    这是一个创建于 2772 天前的主题,其中的信息可能已经有所发展或是发生改变。

    运行出现了: File "E:/owncloud/python_test/img_get.py", line 15, in getbaiduimg data = BeautifulSoup(html,lxml) File "C:\Users\16649\Anaconda3\lib\site-packages\bs4_init_.py", line 149, in init if features is None or len(features) == 0: TypeError: object of type 'module' has no len()

    源码: import lxml import requests from bs4 import BeautifulSoup

    def getbaiduimg(URL): HEADERS = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36", "DNT":"1" } html = requests.get(URL,headers=HEADERS) print(html.text) shtml = html.text data = BeautifulSoup(shtml,lxml)

    #tiebaurl = input('please input your baidu tieba url : ')

    getbaiduimg('https://www.v2ex.com/')

    怎么会出现这种情况呢,本人小白。。求大神帮忙解决下

    4 条回复    2016-08-25 20:32:47 +08:00
    tomczhen
        1
    tomczhen  
       2016-08-25 19:51:24 +08:00
    你为什么不问问神奇海螺呢?
    holajamc
        2
    holajamc  
       2016-08-25 20:14:53 +08:00   ❤️ 1
    额建议你用 md 写问题,我试了试直接复制你的代码没有问题,没有用 lxml ,使用的是 html.parser
    lxy
        3
    lxy  
       2016-08-25 20:23:00 +08:00   ❤️ 1
    lxml 不是这样引入的吧。
    BeautifulSoup(markup, "lxml")

    https://www.crummy.com/software/BeautifulSoup/bs4/doc/
    csy123
        4
    csy123  
    OP
       2016-08-25 20:32:47 +08:00
    @lxy 原来就是这个问题。。好久没写代码都忘了。

    @holajamc 当时忘了加 md 的标签了。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3200 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:25 · PVG 22:25 · LAX 07:25 · JFK 10:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.