bs4中的select选择器(也就是css选择器)用不了解决方法

奇葩的事件 bs4中的select方法css选择器在我的环境中失效;我需要学习下调试,或者是溯源工作,为什么报错
是我的问题,还是bs4在python3.6.7环境下有漏洞

from bs4 import BeautifulSoup

html = '''
<div>
    <ul>
        <li class="item1" value1="1234" value2 = "hello world"><a href="https://geekori.com"> geekori.com</a></li>
        <li class="item"><a href="https://www.jd.com"> 京东商城</a></li>        
    </ul>
    <button id="button1">确定</button>
    <ul>
        <li class="item3"><a href="https://www.taobao.com">淘宝</a></li>
        <li class="item" ><a href="https://www.microsoft.com">微软</a></li>
        <li class="item2"><a href="https://www.google.com">谷歌</a></li>
    </ul>
</div>

'''

soup = BeautifulSoup(html,'lxml')
# tags = soup.select('.item') # select选择器失效么;
# for tag in tags:
#     print(tag)

# tags = soup.select('#button1')
# print(tags)
tags = soup.select('a')
for tag in tags:
    print(tag)

报错图片,真的是见了鬼,别人环境下可以,我不行,报错代码
 'NoneType' object is not callable

12月11号重新回顾代码
删除beautifulsoup4报错代码

pip uninstall beautifulsoup4


之前其实删除过,但好像保留了beautifulsoup4-4.0.0b3-py3.6
这个文件在pip list中显示,我以为就是beautifulsoup4了只是版本不同;删除该文件然后pip install beautifulsoup4
即可。
这就是为什么我bs4模块中的select选择器经常无法使用的缘由,报这个错误TypeError: 'NoneType' object is not callable
在这里记录

posted @ 2021-09-05 19:28  索匣  阅读(994)  评论(2编辑  收藏  举报