[Python] Scraping encoded data from Oddsportal

Discussão em 'Python' iniciado por Stack, Dezembro 1, 2024.

  1. Stack

    Stack Membro Participativo

    Oddsportal.com provides odds data from several betting sites. I've been scraping the data for years but they have recently encoded their data and I haven't found a way to decode it.

    Example: https://www.oddsportal.com/football/england/premier-league/liverpool-manchester-city-82qTWLi3/#1X2;2

    The odds data is automatically updated and the data is retrieved from: https://www.oddsportal.com/feed/match-event/1-1-82qTWLi3-1-2-yj30c.dat (the XXX in yjXXX.dat may sometimes change)

    The read data should be in json format.

    The following Python script reads the data (some headers might not be mandatory):

    import urllib.request

    url = 'https://www.oddsportal.com/feed/match-event/1-1-82qTWLi3-1-2-yjdca.dat'

    headers = {
    'authority': 'www.oddsportal.com',
    'method': 'GET',
    'scheme': 'https',
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'deflate',
    'accept-language': 'en-US,en;q=0.9,fi-FI;q=0.8,fi;q=0.7',
    'content-type': 'application/json',
    'referer': 'https://www.oddsportal.com/matches/hockey/20240109',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest'
    }

    req = urllib.request.Request(url, headers=headers)

    text = urllib.request.urlopen(req).read().decode('utf-8')

    print(text[:80])

    print('string length:', len(text))


    Output:

    NFBSamc0SmVBREJnQVgwMm9Ld0IwMll1VXNBVEYyckdONHJnL3ljUEtYSjlJVDZ5Q0ZWNmlkeWcxYnJy
    string length: 187240


    Any ideas how to decode the data?

    Continue reading...

Compartilhe esta Página