【发布时间】:2019-05-17 22:48:23
【问题描述】:
我正在尝试获取特定 td 内的第二个标签,但我无法仅获取第二个标签的文本,因为我正在从所有 a. 后面我会做一个for来获取10个td的数据。正如您在图片中看到的,我想要 10 个 td 中的每一个中的第二个 a 的数据:
我的代码:
from requests import get
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
url = 'https://www.oddsportal.com/soccer/spain/laliga'
response = get(url, headers=headers)
html_soup = BeautifulSoup(response.text, 'html.parser')
type(html_soup)
match_containers = html_soup.find_all("td",{ "class" : "name table-participant"})
print(len(match_containers))
first_match = match_containers[0]
first_title = first_match.text
print (first_title)
【问题讨论】:
标签: python web-scraping beautifulsoup tags findall