Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.37 KB | None | 0 0
  1. ## Подключение библиотек веб-драйвера, времени, парсинга
  2. from selenium.common.exceptions import NoSuchElementException
  3. from selenium.webdriver.chrome.options import Options
  4. from selenium import webdriver
  5. import datetime
  6. import time
  7. from bs4 import BeautifulSoup
  8.  
  9.  
  10. ## Выставление опций для запуска веб-драйвера
  11. chrome_options = Options()
  12. # Опции которые запускают браузер в консольном режиме(без окон)
  13. # chrome_options.add_argument("--headless")
  14. # chrome_options.add_argument("--disable-gpu")
  15. service_log_path = "chromedriver.log"
  16. # service_args = ['--verbose']
  17.  
  18. ## Инициализация драйвера
  19. driver = webdriver.Chrome('chromedriver',
  20.                             chrome_options=chrome_options,
  21.                             service_log_path=service_log_path)
  22. ## Открытие страницы
  23. driver.get('https://www.leon.ru/stavki-live')
  24.  
  25. ## Подождать до загрузки
  26. time.sleep(5)
  27.  
  28. label = 'leon'
  29. result = []
  30.  
  31. ## Скопировать DOM страницы в нашу переменную page
  32. page = driver.page_source
  33. ## Закрыть драйвер
  34. driver.quit()
  35.  
  36. soup = BeautifulSoup(page, 'html.parser')
  37. h_rates_list = []
  38. h_rates = soup.find("table", {"id" : 'theSportsTable'}).find("tbody").find("tr").findAll("th", {"class" : 'text-center'})
  39. if len(h_rates):
  40.     for h_rate in h_rates:
  41.         h_rates_list.append(h_rate.text)
  42. champs = soup.find("div", {"class" : 'main'}).find("table", {"id" : 'theSportsTable'}).find("tbody").findAll("tr")[1:]
  43. if len(champs):
  44.     for event in champs:
  45.         teams = event.find("td", {"class" : 'custmatchestd'}).find("b", {"class" : 'liveeventTeam'}).text
  46.         sport_name = event.find("td", {"class" : 'custmatchestd'}).find("span", {"class" : 'smallgrey liveeventLeague'}).text.split(" -")[0]
  47.         league_name = event.find("td", {"class" : 'custmatchestd'}).find("span", {"class" : 'smallgrey liveeventLeague'}).text.split(" -",1)[1]
  48.         event_bets = event.findAll("div", {"class" : 'val'})
  49.         event_bets_dict = {}
  50.         if event_bets:
  51.             for i in range(3):
  52.                 event_bets_dict[h_rates_list[i]] = event_bets[i].text
  53.             print(sport_name, teams, event_bets_dict)
  54.         else:
  55.             continue
  56.  
  57.  
  58. #         match = {} #Создали словарь под всё событие
  59. #         events = champ.findAll("div", {"class" : 'c-events__item_col'}) #Нашли все события в чемпионате
  60. #         if len(events):
  61. #             for event in events:
  62. #                 teams = event.find("div", {"class" : 'c-events__item'}).find("a", {"class" : 'c-events__name'}).find("span", {"class" : 'c-events__teams'}).get("title") #Нашли названия команд в событии
  63. #                 event_bets = event.find("div", {"class" : 'c-bets'}).findAll("a")
  64. #                 event_bets_dict = {}
  65. #                 for index, event_bet in enumerate(event_bets):
  66. #                     event_bets_dict[h_rates_list[index]] = event_bet.text
  67. #                 match["КФ"] = event_bets_dict
  68. #                 match["Вид спорта"] = sport_name
  69. #                 match["Лига"] = league_name
  70. #                 match["Команды"] = teams
  71. #                 print(match)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement