import requests from bs4 import BeautifulSoup import datetime import traceback URL = r'https://www.betshoot.com/dropping-odds/' def get_content(url): headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8', 'Accept-Language': 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3', 'Accept-Encoding': 'gzip, deflate, br', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0'} try: resp = requests.get(url, headers=headers) if resp.status_code == 200: return 0, resp.content else: return 1, resp.status_code except Exception as e: return 2, traceback.format_exc() def logger(data): print(f'{datetime.datetime.now()} | {data}') def find_table(soup: BeautifulSoup): try: soup = BeautifulSoup(soup, 'lxml') search = soup.find_all('div', class_='dfem') if search: return 0, search else: return 1, f'search: {len(search)}' except Exception as e: return 2, traceback.format_exc() def get_data_from_row(row:BeautifulSoup): try: d1 = {} column_names = ['pre', 'datetime', 'match', '1', 'x', '2', 'O 2.5', 'U 2.5'] for k, i in zip(column_names, row.find_all('div')[:-1]): if len(i.contents) == 1: d1[k] = i.contents[0] elif i['class'][0] == 'arrown': d1[k] = (i.contents[0], i.contents[2]) else: d1[k] = (i.contents[0], i.find('a').text, i['class'][0]) return 0, d1 except Exception as e: return 2, traceback.format_exc() def get_data_from_table(table): try: out = [] for i in table: data = get_data_from_row(i) if data[0]: logger(data[1]) else: out.append(data[1]) return 0, out except Exception as e: return 2, traceback.format_exc() def get_data_from_url(url): data = get_content(url) if data[0]: logger(data[1]) return table = find_table(data[1]) if table[0]: logger(table[1]) return result = get_data_from_table(table[1]) if result[0]: logger(result[1]) return return result[1] if __name__ == '__main__': data = get_data_from_url(URL) print(data)
нужно проверять, может что попало насобирать