如何从此给定的HTML解析树中提取数值($ 54,85​​7.85)?

发布于 2025-02-11 05:09:12 字数 406 浏览 3 评论 0原文

我一直在尝试使用Python Beautifulsoup学习网络刮擦。但是,我在代码上遇到了一些麻烦,因为它不允许我简单地使用此代码访问此值:


value = doc.find_all(class_="bg-theme-p-4 whitespace-nowrap text-sm text-theme-text")
print(value)

这是感兴趣的html树图像

lest.text基本上是我通过请求模块访问的HTML地址。

打印(值)条目不返回任何内容,而是打印出结果[]。 如何访问具有上述类的所有相关值?

I've been trying to learn web scraping using Python BeautifulSoup. However, I'm running into some trouble with my code, as it does not allow me to simply access this value using this code:


value = doc.find_all(class_="bg-theme-p-4 whitespace-nowrap text-sm text-theme-text")
print(value)

This is the html tree image of interest

where result.text is basically the html address that I have accessed through requests module.

The print(value) entry doesn't return anything, instead prints out the result [].
How can i access all the relevant values which have the class as written above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2025-02-18 05:09:12

使用剥离式属性属性:;

soup = BeautifulSoup(html)
>>> print ' '.join(soup.find('td', {'class': 'bg-theme-p-4 whitespace-nowrap text-sm text-theme-text'}).stripped_strings)

Use stripped_strings property:;

soup = BeautifulSoup(html)
>>> print ' '.join(soup.find('td', {'class': 'bg-theme-p-4 whitespace-nowrap text-sm text-theme-text'}).stripped_strings)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文