Python中的Webscraper如何提取所需的精确文本?

2024-10-03 00:26:35 发布

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

你好

我正试着写我的第一个网络垃圾。我设法写了以下内容:

import requests
from bs4 import BeautifulSoup

s = requests.Session()

r = s.get("http://www.sharenet.co.za/v3/quickshare.php?scode=BTI")

r = s.post("http://www.sharenet.co.za/v3/quickshare.php?scode=BTI")

soup = BeautifulSoup(r.text, "html.parser")
print(soup.find_all("td", class_="dataCell"))

我正试图提取一个股价。检查元素时,这是HTML代码:

<td class="dataCell" align="right">85221</td>

Image of share price table

基本上,我的问题是,可以搜索所有的标签,但不能提取确切的标签我想要的。你知道吗

提前谢谢你的帮助。你知道吗


Tags: importhttpwwwv3requeststdphpsoup