我试图访问网站“https://veri.bet/simulator“,然后“访问投注模拟器”按钮,然后下载体育线路信息并以JSON格式显示它们。然而,我在控制台上得到一个空白列表。我做错了什么?我是网络抓取新手。
import requests
from bs4 import BeautifulSoup
import dataclasses
import json
@dataclasses.dataclass
class Item:
sport_league: str = '' # sport as we classify it, e.g. baseball, basketball, football
event_date_utc: str = '' # date of the event, in UTC, ISO format
team1: str = '' # team 1 name
team2: str = '' # team 2 name
pitcher: str = '' # optional, pitcher for baseball
period: str = '' # full time, 1st half, 1st quarter and so on
line_type: str = '' # whatever site reports as line type, e.g. moneyline, spread, over/under
price: str = '' # price site reports, e.g. '-133' or '+105'
side: str = '' # side of the bet for over/under, e.g. 'over', 'under'
team: str = '' # team name, for over/under bets this will be either team name or total
spread: float = 0.0 # for handicap and over/under bets, e.g. -1.5, +2.5
def parse_betting_line(row):
item = Item()
item.sport_league = row.find('span', {'class': 'sport-league'}).text.strip()
item.event_date_utc = row.find('span', {'class': 'event-date-utc'}).text.strip()
item.team1 = row.find('span', {'class': 'team1'}).text.strip()
item.team2 = row.find('span', {'class': 'team2'}).text.strip()
item.pitcher = row.find('span', {'class': 'pitcher'}).text.strip()
item.period = row.find('span', {'class': 'period'}).text.strip()
item.line_type = row.find('span', {'class': 'line-type'}).text.strip()
item.price = row.find('span', {'class': 'price'}).text.strip()
item.side = row.find('span', {'class': 'side'}).text.strip()
item.team = row.find('span', {'class': 'team'}).text.strip()
if item.line_type in ['spread', 'over/under']:
item.spread = float(row.find('span', {'class': 'spread'}).text.strip())
return item
def main():
response = requests.get('https://veri.bet/simulator')
soup = BeautifulSoup(response.content, 'html.parser')
betting_lines = []
for row in soup.find_all('div', {'class': 'betting-line'}):
betting_lines.append(parse_betting_line(row))
print(json.dumps(betting_lines, indent=2))
if __name__ == '__main__':
main()
字符串
1条答案
按热度按时间iqxoj9l91#
网站还没有“投注线”类,访问投注模拟器去https://veri.bet/odds-picks?filter=upcoming和获取数据从aublesshttps://veri.bet/x-ajax-oddspicks?filter=upcoming&showAll=yes.所以你可以像这样废弃它:
字符串
输出:
型