Advertisement
BrotherCash

Untitled

Jan 11th, 2021
1,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. # import libraries
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. # set variables
  6. url = "https://codercc.svc.4prj.ru/stat/monthly/1"
  7. page = requests.get(url)
  8. year_dict = {}
  9.  
  10. # Create a BeautifulSoup object
  11. soup = BeautifulSoup(page.text, 'html.parser')
  12.  
  13. # Pull section with data
  14. stat_table = soup.find(class_='row')
  15. stat_boxes = stat_table.find_all('div', class_='box')
  16.  
  17. for stat_box in stat_boxes:
  18.     box_header = stat_box.find('h3')
  19.     print(box_header.get_text())
  20.     box_table = stat_box.find('table')
  21.     box_rows = box_table.find_all('tr')
  22.     for row in box_rows:
  23.         name = row.find_all('a', role="button")
  24.         hidden_table = row.find_all('table')
  25.         if len(hidden_table) > 0:
  26.             hidden_table[0].decompose()
  27.         columns = row.find_all('td')
  28.         if len(name) > 0:
  29.             n = name[0]
  30.             print(n.text)
  31.             scores = columns[6].text
  32.             print(scores)
  33.  
  34.  
  35. # get date from the content
  36. content = soup.find(class_='content')
  37. children = content.findChildren()
  38. for child in children:
  39.     child.decompose()
  40. date = content.get_text()
  41. date = date.strip()
  42. date = date.split(' ')
  43. year_dict[date[1]] = {}
  44.  
  45. print(year_dict)
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement