0

I'm trying to get the chart data stored in div data-moves= list of dictionaries from this bs4.element.Tag (data) and cant seem to figure out why it's not working.

The data I want is:

<div id="event-swing-container" data-moves='[{"name":"Change since opening","data":[["Magomed Ankalaev",-73],["Azamat Murzakanov",-56],....,["Marlon Moraes",1]],"visible":false}]' id="event-swing-container" style="height: 230px;"></div>

Here's my code so far:

from bs4 import BeautifulSoup
import requests
URL = 'https://www.bestfightodds.com/events/ufc-2414'
page = requests.get(URL)

esoup = BeautifulSoup(page.content, "html.parser")
data = esoup.find('div', id='event-swing-container')
4
  • @ggorlen i added an image, hope that helps. Thanks Commented Mar 11, 2022 at 22:19
  • @ggorlen Think i fixed my post and added the minimal code possible, sorry for the trouble. Thanks again Commented Mar 12, 2022 at 13:14
  • Much clearer, thanks. Voted to reopen and upvoted. That said, How find specific data attribute from html tag in BeautifulSoup4? may be able to solve your problem, along with json.loads() once you have the contents of data-moves. Commented Mar 12, 2022 at 14:37
  • 1
    data.attrs actually returns the dictionary and then i used json.loads to convert over. Thanks for helping with this silly question =) @ggorlen Commented Mar 12, 2022 at 19:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.