zoukankan      html  css  js  c++  java
  • beautifulsoup4库安装、使用

    (venv) D:pytest>pip install beautifulsoup
    Collecting beautifulsoup
      Using cached https://files.pythonhosted.org/packages/1e/ee/295988deca1a5a7accd783d0dfe14524867e31abb05b6c0eeceee49c759d/BeautifulSoup-3.2.1.tar.gz
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "C:Users1AppDataLocalTemppip-install-mav7d0boeautifulsoupsetup.py", line 22
            print "Unit tests have failed!"
                                          ^
        SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Unit tests have failed!")?
    
        ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in C:Users1AppDataLocalTemppip-install-mav7d0boeautifulsoup
    

    哦,大概是beautifulsoup已经被炸了,需要pip install beautifulsoup4 或者直接bs4


    BeautifulSoup类的基本元素

    基本元素 说明
    Tag 标签,最基本的信息组织单元,分别用<>  和</>标明开头和结尾
    Name 标签的名字,<p>…</p>的名字是'p',格式:<tag>.name
    Attributes 标签的属性,字典形式组织,格式:<tag>.attrs
    NavigableString 标签内非属性字符串,<>…</>中字符串,格式:<tag>.string
    Comment 标签内字符串的注释部分,一种特殊的Comment类型

    标签树的下行遍历

    属性 说明
    .contents 子节点的列表,将<tag>所有儿子节点存入列表
    .children 子节点的迭代类型,与.contents类似,用于循环遍历儿子节点
    .descendants 子孙节点的迭代类型,包含所有子孙节点,用于循环遍历




  • 相关阅读:
    【BUUCTF】WEB SECRET FILE
    你是如何让函数返回IEnumerable<T>的
    对Closure的再思考
    旋转的女郎
    Tools in Visual Studio 2010
    解析命令行的正则表达式
    Closure中关于递归的一点补充
    对C++和C#中多态及类型转换的理解(二)
    对C#和C++0x中Lamda表达式的简略对比
    对C++和C#中多态及类型转换的理解(一)
  • 原文地址:https://www.cnblogs.com/p36606jp/p/15113887.html
Copyright © 2011-2022 走看看