-1

I managed to build a query tool that iterates through a list of fighter names to obtain their unique url on bestfightodds.com.

However, now I am in conflict regarding how I can iterate a fighter's website to search the closing odds given a certain fighter's opponent.

For example, say I have Jon Jones' unique fighter page - https://www.bestfightodds.com/fighters/Jon-Jones-819, and an opponent (for example we will choose Daniel Cormier). I would like to return a list of Jon Jones' closing odds for the fights: [-310, -192].

The issue is that I don't have an idea as to how I can link together the opponent's html text to find the respective odds.

I tried iterating through the html text, but was not able to link the fighter name to their respective odds.

baduker
  • 19,152
  • 9
  • 33
  • 56
user54565
  • 21
  • 2

1 Answers1

0

You can first find all td that says UFC 182: Jones vs. Cormier and such. Then find it's parent which is class with main-row if you see site. Then do normal find_all or select_one to find the text.

cormier_closing = [td.parent.find_all(class_='moneyline')[2].text for td in soup.find_all('td', string=re.compile('Cormier'))]

OR

cormier_closing = [td.parent.select_one('td:nth-child(5)').text for td in soup.find_all('td', string=re.compile('Cormier'))]

EDIT:
using previous_sibling to select elements and text inside

opponent = 'Daniel Cormier'    # use full name
closing_2 = []
for opp_name in soup.find_all('a', string=opponent):
    opp_el = opp_name.find_parent('tr')    # opponent element: use find_all to get values for opponent
    fighter_el = opp_el.previous_sibling   # fighter element
    c2 = fighter_el.find_all(class_='moneyline')[2].text    # using find_all to get second closing
    closing_2.append(c2)    # appending to closing_2

Reyot
  • 466
  • 1
  • 3
  • 9
  • This seems to work, however this technique doesn't seem to be adaptable to different combinations. For example if I use Yair Rodriguez and want to find Josh Emmett's odds using this code, with string "Emmett" I get any empty list. – user54565 Jul 18 '23 at 05:28
  • The error was because the website was inconsistent. It was showing `Event: UFC 284: Makhachev vs. Volkanovski` for match between Rodriguez and Emmett. I added another code, you can use that. – Reyot Jul 18 '23 at 11:05