English 中文(简体)
如何打破足球周的成果
原标题:How to scrape football week results

http://docs.google.com/spreadsheets/d/e/2X-1vQ-RXODO0N39YSCLWncqnfRgnxGri31yAzw7fD0xv3Rgl7P5jzgbxmBd7zbrXyjlQZjLII=1CprOkG/pubhtml” 下面是《on法》迄今撰写的。

import requests
from bs4 import BeautifulSoup
import csv
import pandas as pd

page = requests.get( https://odibets.com/league?br=1&tab=results )
soup = BeautifulSoup(page.text,  html.parser )
table = soup.find(class_="l-league-table-results" )

results = table.find_all(class_= results )
for i in results:
        weeks = i.find(class_= results-title ).getText()
        week = weeks[55:58]
        

        day = i.find_all(class_= results-body )[3]
        home = day.find_all( td )[0].getText()
        away = day.find_all( td )[2].getText()
        score = day.find_all( td )[1].getText()
        homeScore = score[:1]
        awayScore = score[1:]
        print(awayScore)

• 如何写成该法典,以取得与以下网站所示相同的结果:excel file

最佳回答

该书将刊印周、团队和记分:

import requests
from bs4 import BeautifulSoup


url =  https://odibets.com/league?br=1&tab=results 
soup = BeautifulSoup(requests.get(url).content,  html.parser )

print( {:<5}{:<25}{:<25}{:<12}{:<12} .format( WEEK ,  HOME ,  AWAY ,  HOME SCORE ,  AWAY SCORE ))
for row in soup.select( tr.results-body ):
    week = row.find_previous( td , colspan="3").text.split()[3]
    home_team, home_score, away_score, away_team = row.get_text(strip=True, separator= | ).split( | )
    print( {:<5}{:<25}{:<25}{:<12}{:<12} .format(week, home_team, away_team, home_score, away_score))

印刷:

WEEK HOME                     AWAY                     HOME SCORE  AWAY SCORE  
34   NORWICH                  Burnley                  1           1           
34   Manchester Reds          Wolves                   2           2           
34   SHEFFIELD U              Liverpool                0           1           
34   ASTON V                  Brighton                 1           2           
34   London Reds              Leicester                2           3           
34   Tottenham                Bournemouth              0           0           
34   Newcastle                Manchester Blue          1           4           
34   Southampton              Palace                   2           0           
34   West Ham                 Watford                  0           0           
34   London Blues             Everton                  3           1           
33   Bournemouth              NORWICH                  1           0           
33   Watford                  London Blues             0           0           
33   Wolves                   ASTON V                  4           0           
33   Burnley                  SHEFFIELD U              2           1           
33   Palace                   London Reds              0           1           
33   Brighton                 West Ham                 0           0           
33   Manchester Reds          Tottenham                1           4           
33   Everton                  Newcastle                2           1           
33   Leicester                Manchester Blue          1           3           
33   Liverpool                Southampton              1           0           
32   Southampton              Burnley                  3           2           
32   West Ham                 Wolves                   0           2           
32   London Blues             Brighton                 0           2           
32   Tottenham                NORWICH                  1           0           

...and so on.
问题回答
import requests
from bs4 import BeautifulSoup


url =  https://odibets.com/league?br=1&tab=results 
soup = BeautifulSoup(requests.get(url).content,  html.parser )

print( {:<5}{:<25}{:<25}{:<12}{:<12} .format( WEEK ,  HOME ,  AWAY ,  HOME SCORE ,  AWAY SCORE ))
for row in soup.select( tr.results-body ):
    week = row.find_previous( td , colspan="3").text.split()[3]
    home_team, home_score, away_score, away_team = row.get_text(strip=True, separator= | ).split( | )
    print( {:<5}{:<25}{:<25}{:<12}{:<12} .




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签