Skip to content

Instantly share code, notes, and snippets.

@derek-adair
Last active May 9, 2020 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derek-adair/abd5f8bbb36af773c58423109cd9675c to your computer and use it in GitHub Desktop.
Save derek-adair/abd5f8bbb36af773c58423109cd9675c to your computer and use it in GitHub Desktop.
Python script to show how many dependencies each package has
import requests
import json
import lxml.html
from lxml.cssselect import CSSSelector
f = open('package.json')
packageJson = json.load(f)
for dep in packageJson['dependencies']:
response = requests.get('https://www.npmjs.com/package/{}?activeTab=dependencies'.format(dep)) tree = lxml.html.fromstring(response.text) sel = CSSSelector('#dependencies h2:first-child') results = sel(tree) print ("{} has....".format(dep))
print (lxml.html.tostring(results[0]))
print ("----------------------------------------")
requests
lxml
cssselect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment