python - 跨度解析python
问题描述
我是这里的新用户。我在通过 beautifullsoup(python) 解析数据时遇到问题。我有这样的跨度:
<span class="kolesa-score-label cheaper">
<span class="kolesa-score-label-on">на</span>
2.93% дешевле
</span>
我需要得到 2.93
deshevle = soup.find_all('span', class_='kolesa-score-label cheaper').text
不管用。
还有一个问题是:
for div in soup.find_all('div', attrs={'class': 'row vw-item list-item blue a-elem'}):
adv_id=str(div.find('a')['data-product-id'])
它只记录最后一个周期。为什么?因为我想把它当作清单......已经尝试过adv_id=[]
,没有任何改变
解决方案
adv_id=str(div.find('a')['data-product-id'])
试试 adv_id.append 吧?(在 adv_id=[] ofc 之后)
但如果你想要一个列表,你应该像一个列表一样思考,根本不使用 append:
adv_id = [str(div.find('a')['data-product-id']) for div in soup.find_all('div', attrs={'class': 'row vw-item list-item blue一个元素'})]
列表理解: https ://docs.python.org/3/tutorial/datastructures.html#list-comprehensions
PS:不知道你的美丽汤,我只是在这里嫖一些蟒蛇的名声
推荐阅读
- visual-studio-2019 - Visual Studo 2019 可以在项目根目录中打开文件吗?
- php - 如何从列中提取数据并插入数组并添加值
- ios - Swift - 滚动视图中的内容被砍掉
- linux - 解压部分文件
- machine-learning - 竞争学习 ANN 输出层的神经元数量
- android - 如何覆盖焦点按钮元素样式android?
- html - 使用 Observable 与另一个 Observable 一起工作
- node.js - 如何在节点js中读取文件?
- reactjs - React - 在第一列和最后一列中插入材料表操作
- javascript - 如何使用目录的 sas 令牌列出目录内容