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

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

copyfrom 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报错代码

copypip uninstall beautifulsoup4


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

posted @   索匣  阅读(1037)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示