Skip to content
Advertisement

Is there a way to scrape HTML popup tables/charts with python?

I’m currently looking to scrape https://www.bestfightodds.com/ for an MMA machine learning project. I’m specifically looking for the DraftKings opening odds for each fighter which is found by clicking on the odds for a given fighter under the DraftKings column. You are then presented with a popup table that shows how the betting odds have changed over time. The table presents you with the openings odds and the latest (current) odds.

I have no issue scraping the fighter names, but I can’t figure out how to scrape the opening odds in the popup table. The HTML code from the popup table only appears in the inspect function when you click on it which is why I get a ‘None’ when I try to find it in the site’s HTML.

This is my code so far:

JavaScript

Here is a photo of where and how to locate the opening odds. The blue box is where you click to find the red one, which is the one I need to scrape for all fighters.

Advertisement

Answer

Fun little project. The data the server sends are encoded by custom JavaScript function, so you need to use selenium or rewrite the decoding function to Python.

I used js2py to execute the javascript function directly in python (and not use selenium – it rewrites the javascript function to python automatically), but you can rewrite it to Python if you wish:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement