1

i'm trying to extract,using beautiful soup and python,all the odds from this website

http://www.sportstats.com/soccer/italy/serie-a-2013-2014/sampdoria-napoli-zZAT2c14/#odds/1X2/s3

they are divided in different tables depending on wich type do they are.

Ex:the first table under the div id="betType_1_2" represents odds of type 1X2 of "full time"

I tried to search for all class="odds" but it return also odds from others tables. Have anyone idea on how to extract and then scrape only one table per time by its "div id"?Then i would be able to search for class="odds" and obtain the data i need. Thank you all and sorry for my bad english!!

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Andrea
  • 33
  • 3

1 Answers1

1

You can use CSS selectors to get to the table rows in the desired div:

from bs4 import BeautifulSoup
import requests


url = "http://www.sportstats.com/soccer/italy/serie-a-2013-2014/sampdoria-napoli-zZAT2c14/?block=3"
soup = BeautifulSoup(requests.get(url).content)

id_ = "betType_1_2"
for item in soup.select('div#{id} table.oddsTable tr'.format(id=id_))[1:-1]:
    print [td.text for td in item('td')]

Prints:

[u'bwin', u'3.20', u'3.75', u'2.05']
[u'FortunaWin', u'3.30', u'3.40', u'2.10']
[u'Unibet', u'3.45', u'3.50', u'2.10']
[u'Betclic', u'3.40', u'3.60', u'2.00']
[u'Expekt', u'3.40', u'3.60', u'2.00']
[u'Betsson', u'3.50', u'3.35', u'2.10']
[u'Betsafe', u'3.55', u'3.40', u'2.11']
[u'10Bet', u'3.40', u'3.45', u'2.10']
...
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195