如何使用python在web抓取中选择第二个元素?

2024-04-18 04:07:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试过:

    for row in soup.find("tbody").find_all("tr"):
     col = row.find_all("td")
     date =col[0].text
     revenue = col[1].text.replace("$", "").replace(",", "")
    
    tesla_revenue = tesla_revenue.append({"Date":date, "Revenue":revenue}, ignore_index=True)
tesla_revenue.head()

这就是结果

^{tb1}$

结果显示了左边的表格,但我想在右边有一个,我应该怎么选择下一个tbody? (链接中有截图)

https://i.stack.imgur.com/3Lepx.png


Tags: textinfordatecolallfindtr