2 回答
TA贡献1804条经验 获得超8个赞
尝试这个:
import requests
from bs4 import BeautifulSoup
page = requests.get("https://new.tab.co.nz/extended-form/2020-09-18-m6-r1").text
soup = BeautifulSoup(page, "html.parser")
print(soup.find("h2", {"class": "RaceHeader_title_1Yk"}).text.split()[-1])
输出1600
要获取所有马,请添加以下行:
print([h.text for h in soup.find_all("span", {"class": "EntryHeader_runner_UwW"})])
输出:
['Danny Green (8) 5 g bay', 'Eisenhower (10) 5 g bay', 'On The Rivet (13) 4 g bay', 'Point Break (11) 4 g brown', 'Magie Noire (7) 4 g bay', 'Mazzoni (12) 7 g bay', 'Miss Oaks (3) 5 m bay', 'Turn Your Eyes (6) 5 m chestnut', 'Repulse (5) 4 m bay', 'Spindleshanks (9) 5 m bay', 'Nifty (1) 6 m chestnut', 'Tennessee Rock (14) 4 m bay', 'Wendy Darling (4) 4 m brown', "Tappy's Lad (2) 3 g brown"]
TA贡献1752条经验 获得超4个赞
你可以试试这个:
import requests
from bs4 import BeautifulSoup as bs
# URL to be scrapped
link = "https://new.tab.co.nz/extended-form/2020-09-18-m6-r1"
# Sending a get request to get the content of page
source = requests.get(link).text
# Parsing with help of bs4
soup = bs(source,"html.parser")
# Extracting the specific element from bs4 object
content = soup.find('h2', {'class': 'RaceHeader_title_1Yk'})
# Getting the desired content
result = content.text.split(" ")[-1]
print(result)
输出
1600
添加回答
举报