【发布时间】:2018-08-23 02:18:49
【问题描述】:
希望获取 HTML 表格行中的第一个值。 HTML 表格行看起来像:
Buy Sell Sell
...我的代码如下所示:
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
table = soup.findAll('tr', {'class' :'last'})
for r in range(len(table)):
print(table[r].text)
...当前返回:
Buy
Sell
Sell
...应该,但是我只想检索“购买”值。如果有帮助,该值的 HTML 定位器是
td class = "current" .... </td
我已经尝试在我的代码中使用切片功能 [1]、[-1]、[1:1] 等,但似乎无法弄清楚。有人可以帮忙吗?谢谢一百万。
【问题讨论】:
标签: python html python-3.x beautifulsoup