【问题标题】:Scraping Table BeautifulSoup刮桌 BeautifulSoup
【发布时间】:2021-08-05 07:42:50
【问题描述】:

我想从这个页面https://www.betexplorer.com/soccer/england/premier-league-2019-2020/results/刮一张表我可以得到所有的数据,但我不能得到赔率的列


url = 'https://www.betexplorer.com/soccer/england/premier-league-2019-2020/results/'

r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')


table = soup.find('table', class_="table-main js-tablebanner-t js-tablebanner-ntb") 
for row in table.find_all('tr')[1:]:
    data = row.find_all('td')
    row_data = [td.text.strip() for td in data]
    print(row_data)

输出

['Arsenal - Watford', '3:2', '', '', '', '26.07.2020']
['Burnley - Brighton', '1:2', '', '', '', '26.07.2020']
['Chelsea - Wolves', '2:0', '', '', '', '26.07.2020']
['Crystal Palace - Tottenham', '1:1', '', '', '', '26.07.2020']
['Everton - Bournemouth', '1:3', '', '', '', '26.07.2020']
['Leicester - Manchester Utd', '0:2', '', '', '', '26.07.2020']
['Manchester City - Norwich', '5:0', '', '', '', '26.07.2020']
['Newcastle - Liverpool', '1:3', '', '', '', '26.07.2020']
['Southampton - Sheffield Utd', '3:1', '', '', '', '26.07.2020']
['West Ham - Aston Villa', '1:1', '', '', '', '26.07.2020']
[]

【问题讨论】:

    标签: python beautifulsoup html-table


    【解决方案1】:

    问题在于概率是data-odd 属性的值。因此,你可以做这样的事情(基于克里斯的回答):

    def parse_row(row):
        if data := row.find_all("td"):
            matchup = data[0].text
            result = data[1].text
            odds = []
            for odds_cell in row.find_all("td", {"class": "table-main__odds"}):
                if odds_cell.has_attr("data-odd"):
                    odds += [odds_cell["data-odd"]]
                elif (odds_sub_cell := odds_cell.find(lambda tag: tag.has_attr("data-odd"))):
                    odds += [odds_sub_cell["data-odd"]]
            date = data[-1].text
            # Printing
            print(
                f"{matchup:>32s}  {result:3s}  {odds[0]:>5s} {odds[1]:>5s} {odds[2]:>5s}  {date}")
    
    # Main
    url = 'https://www.betexplorer.com/soccer/england/premier-league-2019-2020/results/'
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'lxml')
    table = soup.find(
        'table', class_="table-main js-tablebanner-t js-tablebanner-ntb")
    for row in table.find_all("tr")[1:]:
        parse_row(row)
    

    给我:

                   Arsenal - Watford  3:2   2.01  3.77  3.55  26.07.2020
                  Burnley - Brighton  1:2   2.62  3.31  2.75  26.07.2020
                    Chelsea - Wolves  2:0   1.91  3.35  4.50  26.07.2020
          Crystal Palace - Tottenham  1:1   6.84  4.44  1.48  26.07.2020
               Everton - Bournemouth  1:3   2.35  3.61  2.90  26.07.2020
          Leicester - Manchester Utd  0:2   3.72  3.57  2.01  26.07.2020
           Manchester City - Norwich  5:0   1.04 19.41 39.82  26.07.2020
               Newcastle - Liverpool  1:3   5.51  4.49  1.56  26.07.2020
         Southampton - Sheffield Utd  3:1   1.98  3.59  3.80  26.07.2020
              West Ham - Aston Villa  1:1   2.61  3.50  2.65  26.07.2020
                 Liverpool - Chelsea  5:3   1.91  3.73  3.95  22.07.2020
           Manchester Utd - West Ham  1:1   1.26  6.36 10.95  22.07.2020
               Aston Villa - Arsenal  1:0   3.11  3.70  2.20  21.07.2020
           Watford - Manchester City  0:4   9.11  6.00  1.30  21.07.2020
                Brighton - Newcastle  0:0   1.99  3.48  3.92  20.07.2020
             Sheffield Utd - Everton  0:1   1.98  3.35  4.15  20.07.2020
             Wolves - Crystal Palace  2:0   1.44  4.22  8.68  20.07.2020
           Bournemouth - Southampton  0:2   2.42  3.72  2.74  19.07.2020
               Tottenham - Leicester  3:0   2.33  3.34  3.15  19.07.2020
                   Norwich - Burnley  0:2   3.21  3.37  2.30  18.07.2020
                  West Ham - Watford  3:1   2.48  2.90  3.34  17.07.2020
     Crystal Palace - Manchester Utd  0:2   8.60  5.23  1.35  16.07.2020
               Everton - Aston Villa  1:1   2.11  3.50  3.47  16.07.2020
           Leicester - Sheffield Utd  2:0   2.14  3.22  3.72  16.07.2020
              Southampton - Brighton  1:1   2.27  3.36  3.24  16.07.2020
                 Arsenal - Liverpool  2:1   4.50  4.18  1.72  15.07.2020
                    Burnley - Wolves  1:1   4.61  3.24  1.93  15.07.2020
       Manchester City - Bournemouth  2:1   1.14  9.01 16.91  15.07.2020
               Newcastle - Tottenham  1:3   5.21  4.06  1.65  15.07.2020
                   Chelsea - Norwich  1:0   1.12  9.49 21.27  14.07.2020
        Manchester Utd - Southampton  2:2   1.27  6.04 10.49  13.07.2020
        Aston Villa - Crystal Palace  2:0   2.35  3.35  3.11  12.07.2020
             Bournemouth - Leicester  4:1   4.90  3.77  1.74  12.07.2020
                 Tottenham - Arsenal  2:1   2.74  3.36  2.61  12.07.2020
                    Wolves - Everton  3:0   2.08  3.16  4.06  12.07.2020
          Brighton - Manchester City  0:5  11.93  6.61  1.24  11.07.2020
                 Liverpool - Burnley  1:1   1.22  6.70 12.88  11.07.2020
                  Norwich - West Ham  0:4   3.64  3.51  2.06  11.07.2020
             Sheffield Utd - Chelsea  3:0   4.89  3.78  1.73  11.07.2020
                 Watford - Newcastle  2:1   1.90  3.50  4.27  11.07.2020
        Aston Villa - Manchester Utd  0:3   8.96  5.59  1.32  09.07.2020
             Bournemouth - Tottenham  0:0   4.74  3.84  1.74  09.07.2020
               Everton - Southampton  1:1   2.08  3.42  3.67  09.07.2020
                Brighton - Liverpool  1:3   6.06  4.02  1.58  08.07.2020
         Manchester City - Newcastle  5:0   1.10 11.14 22.17  08.07.2020
              Sheffield Utd - Wolves  1:0   4.13  3.05  2.09  08.07.2020
                  West Ham - Burnley  0:1   1.84  3.59  4.45  08.07.2020
                 Arsenal - Leicester  1:1   2.20  3.42  3.32  07.07.2020
            Crystal Palace - Chelsea  2:3   7.66  4.34  1.46  07.07.2020
                   Watford - Norwich  2:1   1.75  3.69  4.91  07.07.2020
                 Tottenham - Everton  1:0   1.99  3.52  3.87  06.07.2020
             Burnley - Sheffield Utd  1:1   3.17  2.91  2.59  05.07.2020
             Liverpool - Aston Villa  2:0   1.19  7.48 13.81  05.07.2020
                Newcastle - West Ham  2:2   2.73  3.33  2.64  05.07.2020
       Southampton - Manchester City  1:0   9.01  5.67  1.32  05.07.2020
                   Chelsea - Watford  3:0   1.36  5.03  8.72  04.07.2020
          Leicester - Crystal Palace  3:0   1.65  3.70  5.92  04.07.2020
        Manchester Utd - Bournemouth  5:2   1.19  7.25 15.60  04.07.2020
                  Norwich - Brighton  0:1   3.54  3.26  2.19  04.07.2020
                    Wolves - Arsenal  0:2   2.37  3.16  3.25  04.07.2020
         Manchester City - Liverpool  4:0   2.02  3.73  3.56  02.07.2020
           Sheffield Utd - Tottenham  3:1   4.71  3.66  1.78  02.07.2020
                   Arsenal - Norwich  4:0   1.45  4.81  6.85  01.07.2020
             Bournemouth - Newcastle  1:4   2.18  3.16  3.72  01.07.2020
                 Everton - Leicester  2:1   2.58  3.20  2.89  01.07.2020
                  West Ham - Chelsea  3:2   6.94  4.62  1.46  01.07.2020
           Brighton - Manchester Utd  0:3   6.77  4.12  1.53  30.06.2020
            Crystal Palace - Burnley  0:1   2.01  3.17  4.30  29.06.2020
               Watford - Southampton  1:3   2.38  3.22  3.19  28.06.2020
                Aston Villa - Wolves  0:1   4.49  3.41  1.89  27.06.2020
                   Burnley - Watford  1:0   3.57  3.20  2.21  25.06.2020
           Chelsea - Manchester City  2:1   4.16  3.93  1.82  25.06.2020
               Southampton - Arsenal  0:2   2.65  3.52  2.61  25.06.2020
          Liverpool - Crystal Palace  4:0   1.28  5.70 11.68  24.06.2020
      Manchester Utd - Sheffield Utd  3:0   1.36  4.81  9.50  24.06.2020
             Newcastle - Aston Villa  1:1   2.35  3.34  3.11  24.06.2020
                   Norwich - Everton  0:1   4.42  3.55  1.86  24.06.2020
                Wolves - Bournemouth  1:0   1.57  3.86  6.72  24.06.2020
                Leicester - Brighton  0:0   1.62  3.92  5.85  23.06.2020
                Tottenham - West Ham  2:0   1.56  4.15  6.18  23.06.2020
           Manchester City - Burnley  5:0   1.14  8.75 20.33  22.06.2020
               Aston Villa - Chelsea  1:2   6.97  4.60  1.46  21.06.2020
                 Everton - Liverpool  0:0   5.71  3.96  1.62  21.06.2020
           Newcastle - Sheffield Utd  3:0   3.31  3.02  2.42  21.06.2020
        Bournemouth - Crystal Palace  0:2   2.70  3.08  2.85  20.06.2020
                  Brighton - Arsenal  2:1   3.22  3.37  2.28  20.06.2020
                 Watford - Leicester  1:1   3.78  3.43  2.05  20.06.2020
                   West Ham - Wolves  0:2   4.09  3.38  1.99  20.06.2020
               Norwich - Southampton  0:3   2.91  3.41  2.44  19.06.2020
          Tottenham - Manchester Utd  1:1   3.26  3.43  2.24  19.06.2020
         Aston Villa - Sheffield Utd  0:0   3.28  3.28  2.30  17.06.2020
           Manchester City - Arsenal  3:0   1.28  6.28  9.52  17.06.2020
             Leicester - Aston Villa  4:0   1.52  4.44  6.19  09.03.2020
                   Chelsea - Everton  4:0   1.87  3.79  4.11  08.03.2020
    Manchester Utd - Manchester City  2:0   4.48  3.89  1.78  08.03.2020
                  Arsenal - West Ham  1:0   1.64  4.23  5.08  07.03.2020
                 Burnley - Tottenham  1:1   2.72  3.31  2.67  07.03.2020
            Crystal Palace - Watford  1:0   2.70  3.08  2.88  07.03.2020
             Liverpool - Bournemouth  2:1   1.22  6.99 12.58  07.03.2020
             Sheffield Utd - Norwich  1:0   1.67  3.87  5.35  07.03.2020
             Southampton - Newcastle  0:1   1.73  3.81  4.89  07.03.2020
                   Wolves - Brighton  0:0   1.72  3.72  5.19  07.03.2020
            Everton - Manchester Utd  1:1   2.85  3.31  2.56  01.03.2020
                  Tottenham - Wolves  2:3   2.78  3.07  2.77  01.03.2020
               Bournemouth - Chelsea  2:2   4.12  3.73  1.88  29.02.2020
           Brighton - Crystal Palace  0:1   2.20  3.15  3.68  29.02.2020
                 Newcastle - Burnley  0:0   2.71  3.21  2.75  29.02.2020
                 Watford - Liverpool  3:0   6.74  4.59  1.47  29.02.2020
              West Ham - Southampton  3:1   2.56  3.52  2.70  29.02.2020
                 Norwich - Leicester  1:0   4.17  3.82  1.85  28.02.2020
                Liverpool - West Ham  3:2   1.15  8.56 17.51  24.02.2020
                   Arsenal - Everton  3:2   1.98  3.61  3.81  23.02.2020
            Manchester Utd - Watford  3:0   1.58  3.97  6.21  23.02.2020
                    Wolves - Norwich  3:0   1.51  4.24  6.94  23.02.2020
               Burnley - Bournemouth  3:0   2.23  3.30  3.42  22.02.2020
                 Chelsea - Tottenham  2:1   1.86  3.52  4.49  22.02.2020
          Crystal Palace - Newcastle  1:0   2.17  3.19  3.68  22.02.2020
         Leicester - Manchester City  0:1   5.29  4.45  1.58  22.02.2020
            Sheffield Utd - Brighton  1:1   1.91  3.40  4.37  22.02.2020
           Southampton - Aston Villa  2:0   1.71  4.03  4.69  22.02.2020
          Manchester City - West Ham  2:0   1.12  9.71 19.34  19.02.2020
            Chelsea - Manchester Utd  0:2   1.98  3.42  4.02  17.02.2020
                 Arsenal - Newcastle  4:0   1.45  4.53  7.45  16.02.2020
             Aston Villa - Tottenham  2:3   3.88  3.71  1.94  16.02.2020
                 Norwich - Liverpool  0:1   8.64  5.46  1.34  15.02.2020
               Southampton - Burnley  1:2   1.68  3.95  5.12  15.02.2020
                  Wolves - Leicester  0:0   2.67  3.20  2.80  14.02.2020
         Sheffield Utd - Bournemouth  2:1   1.76  3.43  5.39  09.02.2020
                  Brighton - Watford  1:1   2.30  3.34  3.22  08.02.2020
            Everton - Crystal Palace  3:1   1.65  3.69  5.90  08.02.2020
                   Burnley - Arsenal  0:0   3.93  3.66  1.94  02.02.2020
         Tottenham - Manchester City  2:0   5.86  4.60  1.52  02.02.2020
           Bournemouth - Aston Villa  2:1   2.17  3.36  3.51  01.02.2020
      Crystal Palace - Sheffield Utd  0:1   3.08  3.01  2.58  01.02.2020
                 Leicester - Chelsea  2:2   2.54  3.51  2.73  01.02.2020
             Liverpool - Southampton  4:0   1.30  5.64  9.99  01.02.2020
             Manchester Utd - Wolves  0:0   2.13  3.35  3.65  01.02.2020
                 Newcastle - Norwich  0:0   2.25  3.34  3.34  01.02.2020
                   Watford - Everton  2:3   2.97  3.33  2.45  01.02.2020
                 West Ham - Brighton  3:3   2.51  3.36  2.87  01.02.2020
                West Ham - Liverpool  0:2   8.51  5.35  1.35  29.01.2020
                  Wolves - Liverpool  1:2   5.20  3.94  1.67  23.01.2020
                Leicester - West Ham  4:1   1.47  4.70  6.60  22.01.2020
            Manchester Utd - Burnley  0:2   1.44  4.48  7.78  22.01.2020
                 Tottenham - Norwich  2:1   1.38  5.12  8.19  22.01.2020
               Aston Villa - Watford  2:1   3.10  3.39  2.35  21.01.2020
              Bournemouth - Brighton  3:1   2.85  3.27  2.58  21.01.2020
                   Chelsea - Arsenal  2:2   1.74  3.89  4.75  21.01.2020
        Crystal Palace - Southampton  0:2   2.76  3.16  2.74  21.01.2020
                 Everton - Newcastle  2:2   1.50  4.28  7.11  21.01.2020
     Sheffield Utd - Manchester City  0:1   8.06  4.80  1.41  21.01.2020
                 Burnley - Leicester  2:1   4.28  3.66  1.87  19.01.2020
          Liverpool - Manchester Utd  2:0   1.45  4.60  7.26  19.01.2020
             Arsenal - Sheffield Utd  1:1   1.99  3.38  4.10  18.01.2020
              Brighton - Aston Villa  1:1   1.68  4.15  4.83  18.01.2020
    Manchester City - Crystal Palace  2:2   1.08 11.49 29.28  18.01.2020
                 Newcastle - Chelsea  1:0   5.58  4.36  1.58  18.01.2020
               Norwich - Bournemouth  1:0   2.25  3.47  3.20  18.01.2020
                Southampton - Wolves  2:3   2.59  3.11  2.96  18.01.2020
                 Watford - Tottenham  0:0   3.09  3.60  2.26  18.01.2020
                  West Ham - Everton  1:1   2.91  3.42  2.45  18.01.2020
       Aston Villa - Manchester City  1:6  15.32  9.04  1.15  12.01.2020
               Bournemouth - Watford  0:3   2.54  3.40  2.80  12.01.2020
                   Chelsea - Burnley  3:0   1.34  5.16  9.58  11.01.2020
            Crystal Palace - Arsenal  1:1   4.57  3.86  1.77  11.01.2020
                  Everton - Brighton  1:0   1.93  3.67  3.96  11.01.2020
             Leicester - Southampton  1:2   1.69  3.87  5.08  11.01.2020
            Manchester Utd - Norwich  4:0   1.33  5.45  9.21  11.01.2020
               Tottenham - Liverpool  0:1   4.79  4.03  1.70  11.01.2020
                  Wolves - Newcastle  1:1   1.46  4.42  7.50  11.01.2020
            Sheffield Utd - West Ham  1:0   1.94  3.40  4.26  10.01.2020
           Liverpool - Sheffield Utd  2:0   1.28  5.64 11.53  02.01.2020
            Arsenal - Manchester Utd  2:0   2.64  3.62  2.57  01.01.2020
                  Brighton - Chelsea  1:1   3.86  3.84  1.91  01.01.2020
               Burnley - Aston Villa  1:2   1.96  3.41  4.16  01.01.2020
           Manchester City - Everton  2:1   1.31  5.73  9.07  01.01.2020
               Newcastle - Leicester  0:3   4.19  3.82  1.83  01.01.2020
            Norwich - Crystal Palace  1:1   2.36  3.35  3.09  01.01.2020
             Southampton - Tottenham  1:0   3.52  3.81  2.01  01.01.2020
                    Watford - Wolves  2:1   3.20  3.25  2.36  01.01.2020
              West Ham - Bournemouth  4:0   1.91  3.62  4.10  01.01.2020
                   Arsenal - Chelsea  1:2   2.92  3.65  2.33  29.12.2019
                  Liverpool - Wolves  1:0   1.27  6.07 11.14  29.12.2019
     Manchester City - Sheffield Utd  2:0   1.23  6.86 12.07  29.12.2019
              Brighton - Bournemouth  2:0   1.81  3.77  4.44  28.12.2019
            Burnley - Manchester Utd  0:2   4.20  3.61  1.90  28.12.2019
                 Newcastle - Everton  1:2   3.25  3.31  2.29  28.12.2019
                 Norwich - Tottenham  2:2   4.89  4.41  1.63  28.12.2019
        Southampton - Crystal Palace  1:1   1.95  3.52  4.09  28.12.2019
               Watford - Aston Villa  3:0   1.78  3.99  4.29  28.12.2019
                West Ham - Leicester  1:2   2.54  3.60  2.68  28.12.2019
            Wolves - Manchester City  3:2   6.85  5.28  1.41  27.12.2019
               Aston Villa - Norwich  1:0   2.20  3.71  3.12  26.12.2019
               Bournemouth - Arsenal  1:1   3.85  4.07  1.86  26.12.2019
               Chelsea - Southampton  0:2   1.39  5.02  8.06  26.12.2019
           Crystal Palace - West Ham  2:1   2.25  3.41  3.23  26.12.2019
                   Everton - Burnley  1:0   1.74  3.66  5.11  26.12.2019
               Leicester - Liverpool  0:4   3.54  4.01  1.95  26.12.2019
          Manchester Utd - Newcastle  4:1   1.34  5.29  8.86  26.12.2019
             Sheffield Utd - Watford  1:1   1.82  3.56  4.68  26.12.2019
                Tottenham - Brighton  2:1   1.51  4.45  6.24  26.12.2019
                 Tottenham - Chelsea  0:2   2.33  3.55  3.00  22.12.2019
            Watford - Manchester Utd  2:0   4.74  3.81  1.76  22.12.2019
           Aston Villa - Southampton  1:3   2.49  3.64  2.72  21.12.2019
               Bournemouth - Burnley  0:1   2.39  3.30  3.08  21.12.2019
            Brighton - Sheffield Utd  0:1   2.17  3.35  3.51  21.12.2019
                   Everton - Arsenal  0:0   2.11  3.81  3.24  21.12.2019
         Manchester City - Leicester  3:1   1.37  5.65  7.33  21.12.2019
          Newcastle - Crystal Palace  1:0   2.40  3.09  3.26  21.12.2019
                    Norwich - Wolves  1:2   4.02  3.78  1.89  21.12.2019
           Crystal Palace - Brighton  1:1   2.80  3.22  2.67  16.12.2019
           Arsenal - Manchester City  0:3   6.72  5.72  1.39  15.12.2019
            Manchester Utd - Everton  1:1   1.66  3.96  5.25  15.12.2019
                  Wolves - Tottenham  1:2   2.89  3.56  2.41  15.12.2019
                 Burnley - Newcastle  1:0   1.99  3.43  4.01  14.12.2019
               Chelsea - Bournemouth  0:1   1.22  6.79 12.36  14.12.2019
                 Leicester - Norwich  1:1   1.24  6.69 11.71  14.12.2019
                 Liverpool - Watford  2:0   1.18  7.59 15.17  14.12.2019
         Sheffield Utd - Aston Villa  2:0   1.77  3.87  4.50  14.12.2019
              Southampton - West Ham  0:1   1.81  3.97  4.20  14.12.2019
                  West Ham - Arsenal  1:3   3.58  4.12  1.92  09.12.2019
             Aston Villa - Leicester  1:4   4.87  4.15  1.68  08.12.2019
                   Brighton - Wolves  2:2   2.60  3.18  2.89  08.12.2019
             Newcastle - Southampton  2:1   2.58  3.29  2.82  08.12.2019
             Norwich - Sheffield Utd  1:2   3.14  3.46  2.29  08.12.2019
             Bournemouth - Liverpool  0:3   6.36  4.59  1.49  07.12.2019
                   Everton - Chelsea  3:1   3.30  3.73  2.13  07.12.2019
    Manchester City - Manchester Utd  1:2   1.32  5.69  8.84  07.12.2019
                 Tottenham - Burnley  5:0   1.42  4.81  7.52  07.12.2019
            Watford - Crystal Palace  0:0   2.44  3.32  3.02  07.12.2019
                  Arsenal - Brighton  1:2   1.64  4.24  5.07  05.12.2019
           Sheffield Utd - Newcastle  0:2   1.80  3.52  4.93  05.12.2019
               Chelsea - Aston Villa  2:1   1.34  5.59  8.51  04.12.2019
                 Leicester - Watford  2:0   1.36  5.31  8.52  04.12.2019
                 Liverpool - Everton  5:2   1.61  4.05  5.81  04.12.2019
          Manchester Utd - Tottenham  2:1   2.58  3.39  2.77  04.12.2019
               Southampton - Norwich  2:1   1.78  3.87  4.47  04.12.2019
                   Wolves - West Ham  2:0   1.68  3.94  5.12  04.12.2019
           Burnley - Manchester City  1:4  11.20  6.82  1.24  03.12.2019
        Crystal Palace - Bournemouth  1:0   2.21  3.41  3.34  03.12.2019
                 Leicester - Everton  2:1   1.61  4.08  5.62  01.12.2019
        Manchester Utd - Aston Villa  2:2   1.45  4.69  6.97  01.12.2019
                   Norwich - Arsenal  2:2   4.36  4.38  1.70  01.12.2019
              Wolves - Sheffield Utd  1:1   2.22  3.13  3.65  01.12.2019
            Burnley - Crystal Palace  0:2   2.04  3.42  3.85  30.11.2019
                  Chelsea - West Ham  0:1   1.28  6.09  9.59  30.11.2019
                Liverpool - Brighton  2:1   1.20  7.20 14.36  30.11.2019
         Newcastle - Manchester City  2:2  12.25  7.55  1.20  30.11.2019
               Southampton - Watford  2:1   2.08  3.52  3.57  30.11.2019
             Tottenham - Bournemouth  3:2   1.33  5.55  8.91  30.11.2019
             Aston Villa - Newcastle  2:0   2.18  3.49  3.34  25.11.2019
      Sheffield Utd - Manchester Utd  3:3   3.81  3.33  2.08  24.11.2019
               Arsenal - Southampton  2:2   1.46  4.65  6.87  23.11.2019
                Bournemouth - Wolves  1:2   2.99  3.22  2.51  23.11.2019
                Brighton - Leicester  0:2   3.79  3.56  2.00  23.11.2019
          Crystal Palace - Liverpool  1:2   6.86  4.45  1.48  23.11.2019
                   Everton - Norwich  0:2   1.35  5.34  8.39  23.11.2019
           Manchester City - Chelsea  2:1   1.39  5.47  7.11  23.11.2019
                   Watford - Burnley  0:3   2.23  3.28  3.42  23.11.2019
                West Ham - Tottenham  2:3   4.73  4.31  1.67  23.11.2019
         Liverpool - Manchester City  3:1   2.68  3.61  2.55  10.11.2019
           Manchester Utd - Brighton  3:1   1.63  3.76  6.08  10.11.2019
                Wolves - Aston Villa  2:1   1.70  3.79  5.29  10.11.2019
                  Burnley - West Ham  3:0   2.15  3.60  3.32  09.11.2019
            Chelsea - Crystal Palace  2:0   1.42  4.75  7.61  09.11.2019
                 Leicester - Arsenal  2:0   1.91  3.96  3.77  09.11.2019
             Newcastle - Bournemouth  2:1   2.59  3.24  2.86  09.11.2019
               Southampton - Everton  1:2   3.14  3.34  2.34  09.11.2019
           Tottenham - Sheffield Utd  1:1   1.53  4.28  6.34  09.11.2019
                   Norwich - Watford  0:2   2.87  3.59  2.39  08.11.2019
          Crystal Palace - Leicester  0:2   3.71  3.47  2.06  03.11.2019
                 Everton - Tottenham  1:1   2.48  3.57  2.77  03.11.2019
                    Arsenal - Wolves  1:1   1.75  3.85  4.68  02.11.2019
             Aston Villa - Liverpool  1:2   9.33  6.04  1.30  02.11.2019
        Bournemouth - Manchester Utd  1:0   3.61  3.54  2.07  02.11.2019
                  Brighton - Norwich  2:0   1.58  4.40  5.39  02.11.2019
       Manchester City - Southampton  2:1   1.07 12.89 30.95  02.11.2019
             Sheffield Utd - Burnley  3:0   2.27  3.16  3.48  02.11.2019
                   Watford - Chelsea  1:2   5.14  4.27  1.63  02.11.2019
                West Ham - Newcastle  2:3   1.84  3.70  4.33  02.11.2019
            Arsenal - Crystal Palace  2:2   1.47  4.70  6.58  27.10.2019
               Liverpool - Tottenham  2:1   1.47  4.78  6.38  27.10.2019
                  Newcastle - Wolves  1:1   3.40  3.06  2.37  27.10.2019
            Norwich - Manchester Utd  1:3   4.54  3.73  1.80  27.10.2019
                  Brighton - Everton  3:2   2.66  3.31  2.73  26.10.2019
                   Burnley - Chelsea  2:4   5.03  4.00  1.68  26.10.2019
       Manchester City - Aston Villa  3:0   1.07 13.70 27.21  26.10.2019
               Watford - Bournemouth  0:0   2.27  3.53  3.12  26.10.2019
            West Ham - Sheffield Utd  1:1   2.27  3.39  3.25  26.10.2019
             Southampton - Leicester  0:9   3.11  3.32  2.37  25.10.2019
             Sheffield Utd - Arsenal  1:0   3.65  3.55  2.05  21.10.2019
          Manchester Utd - Liverpool  1:1   4.02  3.49  1.97  20.10.2019
              Aston Villa - Brighton  2:1   2.37  3.43  3.03  19.10.2019
               Bournemouth - Norwich  0:0   1.75  4.21  4.27  19.10.2019
                 Chelsea - Newcastle  1:0   1.28  5.95 10.87  19.10.2019
    Crystal Palace - Manchester City  0:2  11.90  7.18  1.22  19.10.2019
                  Everton - West Ham  2:0   1.79  3.98  4.26  19.10.2019
                 Leicester - Burnley  2:1   1.49  4.36  6.79  19.10.2019
                 Tottenham - Watford  1:1   1.50  4.46  6.53  19.10.2019
                Wolves - Southampton  1:1   2.05  3.26  4.01  19.10.2019
               Arsenal - Bournemouth  1:0   1.36  5.64  7.51  06.10.2019
            Manchester City - Wolves  0:2   1.14  8.85 20.21  06.10.2019
          Newcastle - Manchester Utd  1:0   3.89  3.29  2.07  06.10.2019
               Southampton - Chelsea  1:4   4.66  4.16  1.70  06.10.2019
                Brighton - Tottenham  3:0   4.98  3.89  1.71  05.10.2019
                   Burnley - Everton  1:0   3.16  3.22  2.39  05.10.2019
               Liverpool - Leicester  2:1   1.58  4.33  5.61  05.10.2019
               Norwich - Aston Villa  1:5   2.41  3.58  2.85  05.10.2019
             Watford - Sheffield Utd  0:0   2.34  3.27  3.21  05.10.2019
           West Ham - Crystal Palace  1:2   2.00  3.62  3.75  05.10.2019
            Manchester Utd - Arsenal  1:1   2.23  3.53  3.18  30.09.2019
               Leicester - Newcastle  5:0   1.52  4.15  6.88  29.09.2019
               Aston Villa - Burnley  2:2   2.29  3.40  3.19  28.09.2019
              Bournemouth - West Ham  2:2   2.38  3.60  2.87  28.09.2019
                  Chelsea - Brighton  2:0   1.42  4.72  7.59  28.09.2019
            Crystal Palace - Norwich  2:0   1.91  3.78  3.92  28.09.2019
           Everton - Manchester City  1:3   8.56  5.51  1.34  28.09.2019
           Sheffield Utd - Liverpool  0:1   8.73  5.30  1.35  28.09.2019
             Tottenham - Southampton  2:1   1.38  5.03  8.10  28.09.2019
                    Wolves - Watford  2:0   1.92  3.43  4.27  28.09.2019
               Arsenal - Aston Villa  3:2   1.42  5.04  7.17  22.09.2019
                 Chelsea - Liverpool  1:2   3.23  3.68  2.16  22.09.2019
             Crystal Palace - Wolves  1:1   2.74  3.09  2.82  22.09.2019
           West Ham - Manchester Utd  2:0   3.07  3.46  2.33  22.09.2019
                   Burnley - Norwich  2:0   2.01  3.72  3.60  21.09.2019
             Everton - Sheffield Utd  0:2   1.75  3.56  5.21  21.09.2019
               Leicester - Tottenham  2:1   2.71  3.42  2.61  21.09.2019
           Manchester City - Watford  8:0   1.10 10.62 23.87  21.09.2019
                Newcastle - Brighton  0:0   2.39  3.19  3.21  21.09.2019
           Southampton - Bournemouth  1:3   2.18  3.54  3.31  20.09.2019
              Aston Villa - West Ham  0:0   2.72  3.59  2.51  16.09.2019
               Bournemouth - Everton  3:1   3.31  3.49  2.20  15.09.2019
                   Watford - Arsenal  2:2   4.07  3.86  1.86  15.09.2019
                  Brighton - Burnley  1:1   2.12  3.37  3.62  14.09.2019
               Liverpool - Newcastle  3:1   1.20  7.29 14.34  14.09.2019
          Manchester Utd - Leicester  1:0   2.12  3.35  3.70  14.09.2019
           Norwich - Manchester City  3:2  25.18 11.68  1.09  14.09.2019
         Sheffield Utd - Southampton  0:1   2.46  3.23  3.03  14.09.2019
          Tottenham - Crystal Palace  4:0   1.41  4.91  7.65  14.09.2019
                    Wolves - Chelsea  2:5   3.03  3.39  2.39  14.09.2019
                 Arsenal - Tottenham  2:2   2.57  3.62  2.65  01.09.2019
                    Everton - Wolves  3:2   2.06  3.25  3.99  01.09.2019
                 Burnley - Liverpool  0:3   8.75  5.38  1.34  31.08.2019
             Chelsea - Sheffield Utd  2:2   1.40  4.76  8.16  31.08.2019
        Crystal Palace - Aston Villa  1:0   2.26  3.39  3.27  31.08.2019
             Leicester - Bournemouth  3:1   1.67  4.02  5.12  31.08.2019
          Manchester City - Brighton  4:0   1.09 11.31 29.89  31.08.2019
                 Newcastle - Watford  1:1   2.52  3.18  3.00  31.08.2019
        Southampton - Manchester Utd  1:1   4.05  3.51  1.95  31.08.2019
                  West Ham - Norwich  2:0   1.89  4.00  3.80  31.08.2019
       Bournemouth - Manchester City  1:3  16.22  8.35  1.17  25.08.2019
               Tottenham - Newcastle  0:1   1.28  5.98 10.84  25.08.2019
                    Wolves - Burnley  1:1   1.78  3.46  5.21  25.08.2019
              Brighton - Southampton  0:2   2.35  3.27  3.23  24.08.2019
                 Liverpool - Arsenal  3:1   1.47  4.94  6.33  24.08.2019
     Manchester Utd - Crystal Palace  1:2   1.34  5.27  9.29  24.08.2019
                   Norwich - Chelsea  2:3   4.18  3.87  1.84  24.08.2019
           Sheffield Utd - Leicester  1:2   3.24  3.26  2.34  24.08.2019
                  Watford - West Ham  1:3   2.19  3.51  3.32  24.08.2019
               Aston Villa - Everton  2:0   3.01  3.39  2.41  23.08.2019
             Wolves - Manchester Utd  1:1   3.01  3.28  2.47  19.08.2019
                 Chelsea - Leicester  1:1   1.72  3.83  5.01  18.08.2019
      Sheffield Utd - Crystal Palace  1:0   2.50  3.23  3.00  18.08.2019
                   Arsenal - Burnley  2:1   1.35  5.26  8.81  17.08.2019
           Aston Villa - Bournemouth  1:2   2.25  3.62  3.11  17.08.2019
                 Brighton - West Ham  1:1   2.21  3.43  3.35  17.08.2019
                   Everton - Watford  1:0   1.82  3.68  4.56  17.08.2019
         Manchester City - Tottenham  2:2   1.36  5.45  8.13  17.08.2019
                 Norwich - Newcastle  3:1   2.14  3.42  3.55  17.08.2019
             Southampton - Liverpool  1:2   6.50  4.54  1.49  17.08.2019
                  Leicester - Wolves  0:0   2.40  3.13  3.28  11.08.2019
            Manchester Utd - Chelsea  4:0   2.04  3.35  3.99  11.08.2019
                 Newcastle - Arsenal  0:1   3.36  3.50  2.19  11.08.2019
         Bournemouth - Sheffield Utd  1:1   1.97  3.57  3.95  10.08.2019
               Burnley - Southampton  3:0   2.65  3.17  2.87  10.08.2019
            Crystal Palace - Everton  0:0   3.39  3.36  2.22  10.08.2019
             Tottenham - Aston Villa  3:1   1.36  5.29  8.67  10.08.2019
                  Watford - Brighton  0:3   2.07  3.25  4.02  10.08.2019
          West Ham - Manchester City  0:5  11.02  6.45  1.26  10.08.2019
                 Liverpool - Norwich  4:1   1.13  9.48 19.07  09.08.2019
    

    【讨论】:

    • 我尝试将它运行到另一个页面 betexplorer.com/soccer/italy/serie-a-2019-2020/results 但我得到了IndexError: list index out of range 我认为是因为赔率列缺少一些值跨度>
    • 你是对的。您可以在 parse_row 内部的 for 循环和打印语句之间添加一个简单的检查,例如 odds = ['-']*3 if len(odds) == 0 else odds
    【解决方案2】:

    我猜你正在从这个 HTML 片段中寻找值 2.01、3.77 和 3.55

       <td class="table-main__odds colored" data-oid="3f404xv464x0x8tmer">
         <span><span><span data-odd="2.01"></span></span></span>
       </td>
       <td class="table-main__odds" data-oid="3f404xv498x0x0" data-odd="3.77"></td>
       <td class="table-main__odds" data-oid="3f404xv464x0x8tmes" data-odd="3.55"></td>
    

    您没有找到它们,因为值不是文本,它们是“td”标签的属性。

    所以要做到这一点,代码是这样的

        for odds_cell in row.find_all("td", {"class" : "table-main__odds"}):
            print(odds_cell.attrs['data-odd'])
    

    【讨论】:

    • 这不适用于第一个odd_cell,因为data-odd 是子span 标签的属性。
    • 是的,它不起作用我得到了KeyError: 'data-odd'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多