Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用Beauty soup提取附加数据_Python 3.x_Web Scraping - Fatal编程技术网

Python 3.x 使用Beauty soup提取附加数据

Python 3.x 使用Beauty soup提取附加数据,python-3.x,web-scraping,Python 3.x,Web Scraping,我创建了一个简单的脚本,用于查找在游戏中有预订的玩家。我需要进一步创建两个列表(主客场球队),其中包含球员姓名、预订颜色和时间 import requests from bs4 import BeautifulSoup import warnings warnings.simplefilter(action='ignore') url = 'https://www.fcf.cat/acta/2021/futbol-11/preferent-infantil/grup-1/pi/atletic

我创建了一个简单的脚本,用于查找在游戏中有预订的玩家。我需要进一步创建两个列表(主客场球队),其中包含球员姓名、预订颜色和时间

import requests
from bs4 import BeautifulSoup

import warnings
warnings.simplefilter(action='ignore')

url = 'https://www.fcf.cat/acta/2021/futbol-11/preferent-infantil/grup-1/pi/atletic-sant-just-f-c-a/pi/barcelona-fc-b'


soup = BeautifulSoup(requests.get(url, verify=False).text, 'html.parser')

targeta_g= soup.find_all(class_="groga-s")
targeta_v= soup.find_all(class_="vermella-s")

print (targeta_g)
print (targeta_v)
谢谢

import requests
from bs4 import BeautifulSoup


def get_players(column):
    players = []
    for table in column.select('table:has(th:contains("Targetes"))'):
        for row in table.select('tr:has(td)'):
            tds = [td.get_text(strip=True) for td in row.select('td')]
            players.append([row.span.text, *tds[1:], 'Yellow' if row.select_one('.groga-s') else 'Red'])
    return players


url = 'https://www.fcf.cat/acta/2021/futbol-11/preferent-infantil/grup-1/pi/atletic-sant-just-f-c-a/pi/barcelona-fc-b'
soup = BeautifulSoup(requests.get(url, verify=False).content, 'html.parser')

main_columns = soup.select('.col-md-4.p-0_ml')
players = {'Team Home': get_players(main_columns[0]), 'Team Away': get_players(main_columns[2])}
print(players)
印刷品:

{'Team Home': [['17', 'KOLOMIETS , FYODOR', "22'", 'Red'], ['18', 'RUGGIERO , ANTONIO', "60'", 'Yellow']], 'Team Away': [['11', 'SO DELGADO PINTO, SIDNEY JOSE', "64'", 'Yellow']]}

对于其中一个团队尚未收到卡片的比赛,例如
url='1!'https://www.fcf.cat/acta/2021/futbol-11/preferent-infantil/grup-1/pi/castelldefels-ue-a/pi/rapitenca-ue-b“
它打印:

{'Team Home': [], 'Team Away': [['12', 'BELTRAN SOSPEDRA, MARC', "60'", 'Yellow']]}
印刷品:

{'Team Home': [['17', 'KOLOMIETS , FYODOR', "22'", 'Red'], ['18', 'RUGGIERO , ANTONIO', "60'", 'Yellow']], 'Team Away': [['11', 'SO DELGADO PINTO, SIDNEY JOSE', "64'", 'Yellow']]}

对于其中一个团队尚未收到卡片的比赛,例如
url='1!'https://www.fcf.cat/acta/2021/futbol-11/preferent-infantil/grup-1/pi/castelldefels-ue-a/pi/rapitenca-ue-b“
它打印:

{'Team Home': [], 'Team Away': [['12', 'BELTRAN SOSPEDRA, MARC', "60'", 'Yellow']]}