Skip to content

Instantly share code, notes, and snippets.

@eabase
Created December 18, 2020 23:15
Show Gist options
  • Save eabase/feac16947df00babfe25c1984839eb68 to your computer and use it in GitHub Desktop.
Save eabase/feac16947df00babfe25c1984839eb68 to your computer and use it in GitHub Desktop.
pip search removed - The Return (How hard can it be?)
# Basic pip search function provided by:
# https://pypi.org/project/pip-search/
import sys
from urllib import request
from tabulate import tabulate
def search () :
f = request.urlopen('https://pypi.org/search/?q=%s' % sys.argv[1])
raw_text=str(f.read())
raw_names=raw_text.split('<span class="package-snippet__name">')[1:-2]
names=[]
for name in raw_names :
names.append(name.split('</span>')[0])
raw_desc=raw_text.split('<p class="package-snippet__description">')[1:-2]
descs=[]
for desc in raw_desc :
descs.append(desc.split('</p>')[0])
header=[['Name', 'Description'],['','']]
rows=[[names[i],descs[i]] for i in range(len(names))]
print(tabulate(header+rows))
if __name__ == '__main__':
search()
@eabase
Copy link
Author

eabase commented Dec 30, 2021

For a more advanced handling, please see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment