• Python 库




    1. PySnooper

    python的自动debug工具,只需要在函数上用它装饰,运行程序时,就可以知道每一个程序运行的步骤,参数和返回值,在找错误时非常方便,如下使用

    import pysnooper
     
    @pysnooper.snoop()
    def demo_func():
        profile = {}
        profile["name"] = "写代码的明哥"
        profile["age"] = 27
        profile["gender"] = "male"
     
        return profile
     
    def main():
        profile = demo_func()
     
    main()

     

    2.requests

    这个模块是python用来爬取网站时,获取网站数据,用requests就可以轻松获取到数据,上传或者下载超过2g的大文件都可以。

    In [1]: import requests  
    In [2]: resp = requests.get('http://www.baidu.com')
    
    In [3]: resp.status_code
    Out[3]: 200
    

     

    3.requests-html

     

    这个模块是requests作者写的,也是针对爬虫模块,当我们获取到是一个网页,按照平常我们可能会用lxml解析网页,用这个模块可以省略这个步骤,轻松获取网站的标题,url等

    from requests_html import HTMLSession
    
    session = HTMLSession()
    r = session.get('https://www.qiushibaike.com/text/')
    // 查看页面内容
    print(r.html.html)

     

    4.lxml

     

    我们解析xml通常都用xml.dom模块,可是使用特别的繁琐,所来lxml不仅可以解析html,还可以解析xml,真心好用

    from lxml import etree#导入lxml库
    tree = etree.parse("dblp.xml")#将xml解析为树结构
    root = tree.getroot()#获得该树的树根
  • 相关阅读:
    CF1042E Vasya and Magic Matrix
    Luogu 4868 Preprefix sum
    CF1042F Leaf Sets
    CF1041F Ray in the tube
    【Luogu】P1410子序列(DP)
    【Luogu】P1383高级打字机
    【Luogu】P1681最大正方形2(异或运算,DP)
    【Luogu】P1122最大子树和(DFS,树上DP)
    【Luogu】P2258子矩阵(状态压缩,DP)
    【Luogu】P2158仪仗队(欧拉函数)
  • 原文地址:https://www.cnblogs.com/xiongwei/p/16300156.html
Copyright © 2020-2023  润新知