问题描述
This page https://www.kijiji.ca/v-1-bedroom-apartments-condos/ville-de-montreal/1-chambre-chauff-eau-chaude-incl-vsl-514-856-0038/1334431659 contains this span class:
<span class="currentPrice-3131760660"><span content="800.00">800,00 $</span>
我正在尝试自动提取价格(在本例中为 800 美元).然而,随着时间的推移,currentPrice-"之后的数字发生变化,我的 Python 脚本停止工作.我正在使用这个美丽的汤功能:
I'm trying to automatically extract the price (800$ in this case). Over time, however, the number after "currentPrice-" changes, and my Python script ceases to work. I am using this Beautiful soup function:
soup.find_all('span', {'class' : 'currentPrice-3131760660'})
如何使用 find_all 提取类名称的部分匹配项,例如包含字符串currentPrice-"的所有类?
How can I use find_all to extract partial matches of class names, such as all classes containing the string "currentPrice-"?
推荐答案
你可以试试 CSS 选择器 soup.select('span[class*="currentPrice-"]')
You could try a CSS selector soup.select('span[class*="currentPrice-"]')
这篇关于使用 Beautiful Soup 查找跨度中的部分类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!