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!!

2
  • What is your desired output? Commented Dec 15, 2014 at 14:09
  • it should be something like: 10Bet 3.40 3.45 2.10 188BET 3.40 3.80 2.00 5Dimes 3.54 3.86 2.10 Commented Dec 15, 2014 at 14:17

1 Answer 1

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']
...
Sign up to request clarification or add additional context in comments.

Comments

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.