Skip to content

Instantly share code, notes, and snippets.

@AOx0
Created August 4, 2021 01:37
Show Gist options
  • Save AOx0/2c9f9be978c54d4c7dc3006e3dea0d3e to your computer and use it in GitHub Desktop.
Save AOx0/2c9f9be978c54d4c7dc3006e3dea0d3e to your computer and use it in GitHub Desktop.
Web scraping python script to get a the number of commits of a user
from lxml import html
import requests
elements = list()
date = False
user = 'AOx0'
pagina: requests.Response = requests.get(f'https://github.com/{user}')
tree: html.HtmlElement = html.fromstring(pagina.content)
for i in tree.xpath(
'//*[@id=\"js-pjax-container\"]/div[2]/div/div[2]/div[2]/div/div[contains('
'@class,\"mt-4 position-relative\")]/div[1]/div/div/div/svg/g/g'
):
i: html.HtmlElement
for j in i.getchildren():
j: html.HtmlElement
if date:
elements.append((j.items()[8][1], int(j.items()[7][1])))
else:
elements.append(int(j.items()[7][1]))
print(elements)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment