python - 从 bs4 find_all 函数返回文本
问题描述
我目前正在尝试解决此问题(BeautifulSoup):
crypto_name = soup.find_all("p",class_="sc-1eb5slv-0 iJjGCS") print(crypto_name)
返回:
[<p class="sc-1eb5slv-0 iJjGCS" color="text" font-size="1" font-weight="semibold">Bitcoin</p>, <p class="sc-1eb5slv-0 iJjGCS" color="text" font-size="1" font-weight="semibold">Ethereum</p>
我只需要它来返回比特币和以太币。但我真的不知道该怎么做。
解决方案
循环遍历结果并获得.text
教学项目。
cryptos = [item.text for item in crypto_name]
推荐阅读
- winapi - 如何自动对“云”文件 (OneDrive) 进行无、部分和全部水合以进行测试?
- javascript - 如何为整个表格设置数据表格搜索面板的样式?
- python - 在 pandas 中保留一列的数据并仅显示其他列中的所有 NAN
- reactjs - 不确定这是否是 ReactJS 异步或状态问题,但 inputValue.length 为 0 即使在我 useState() 将 inputValue 设置为等于字符串之后
- mysql - 在具有重叠 ID(主键)的数据库之间传输记录
- jquery - 如何根据 datepicker 选择的日期动态设置 jquery.timepicker minTime?
- python - Python中嵌套函数的性能开销
- typescript - 保留字符串联合和字符串类型以显示提示
- go - 如何在 Go 中编写 LEB128
- php - 设置 PHP 类属性的默认值并在相同的类函数中使用它