zoukankan      html  css  js  c++  java
  • 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
    在这里记录

    努力拼搏吧,不要害怕,不要去规划,不要迷茫。但你一定要在路上一直的走下去,尽管可能停滞不前,但也要走。
  • 相关阅读:
    CentOS7 时间设置与网络同步
    CentOS7 系统升级,删除centos7开机界面多余选,升级至最新的内核
    Docker 编排工具Rancher 2.0
    Docker 编排工具Rancher 1.6.18
    通过WSL在Windows下安装子Linux系统
    Docker 使用Dockerfile构建redis镜像
    初探PHP多进程
    nginx转发
    mime类型
    socket php
  • 原文地址:https://www.cnblogs.com/wkhzwmr/p/15230518.html
Copyright © 2011-2022 走看看