Quantcast
Channel: Web scraping using beautiful soup (sports data) - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Web scraping using beautiful soup (sports data)

$
0
0

When i try loading this code i get two errors.1:The first one is that i can't properly scrape the data for name_text.

2: I get an indentation error for team = name_text.div.text. I know it is probably easy to solve but i have tried different indentations and nothing seems to be working.

in the website I am wanting to scrape the team name and the odds.

<div class="size14_f7opyze Endeavour_fhudrb0 medium_f1wf24vo participantText_fivg86r" data-automation-id="participant-one">Orlando Magic</div><div class="priceText_f71sibe"><span class="size14_f7opyze medium_f1wf24vo priceTextSize_frw9zm9" data-automation-id="price-text">5.85</span></div>

The html above has been copied from the site.

from bs4 import BeautifulSoupfrom urllib.request import urlopen as uReqmy_url = 'https://www.sportsbet.com.au/betting/basketball-us'uClient = uReq(my_url)page_html = uClient.read()uClient.close()soup = BeautifulSoup(page_html, "html.parser")price_text = soup.findAll("div",{"class":"priceText_f71sibe"})name_text = soup.findAll("div",{"class":"size14_f7opyze Endeavour_fhudrb0 medium_f1wf24vo participantText_fivg86r"})filename = "odds.csv"f = open(filename,"w")headers = "Team, odds_team\n"print(name_text)f.write(headers)for price_text in price_texts:team = name_text.div.textodds = price_text.span.textprint(odds)print(team + odds)f.write(team +","+ odds +"\n")f.close()

Any help would be great. Cheers.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images