JSON API for PyPi - how to list packages?

前端 未结 4 2165
后悔当初
后悔当初 2020-12-15 18:33

There is a JSON API for PyPI which allows getting data for packages:

http://pypi.python.org/pypi//json
http://pypi.python.org/pypi/

        
4条回答
  •  难免孤独
    2020-12-15 19:23

    I tried this answer, but it's not working on Python 3.6

    I found one solution with HTML parsing by using lxml package, But you have to install it via pip command as

    pip install lxml
    


    Then, try the following snippet

    from lxml import html
    import requests
    
    response = requests.get("https://pypi.org/simple/")
    
    tree = html.fromstring(response.content)
    
    package_list = [package for package in tree.xpath('//a/text()')]
    

提交回复
热议问题