Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
849 B
7
Indexable
Never
import requests
from bs4 import BeautifulSoup

url = 'https://gambit-table.ru/ls/ucp/'
response = requests.get(url)

if response.status_code == 200:
  soup = BeautifulSoup(response.text, 'html.parser')
  rows = soup.select('tr')
  user_counts = {}

  for row in rows:
    username_element = row.select_one('.tabletd:nth-child(2) div:first-child')
    count_element = row.select_one('.tabletd:nth-child(5) div:first-child')

    if username_element and count_element:
      username = username_element.get_text(strip=True)
      count = count_element.get_text(strip=True)

      if username and count:
        user_counts[username] = user_counts.get(username, 0) + int(count)

  for username, count in user_counts.items():
    print(f'{username} {count}')

else:
  print(f'нэ получилось: {response.status_code}')
Leave a Comment