【发布时间】:2021-05-12 22:05:33
【问题描述】:
从 Poocoin 刮取硬币/代币的价格。这听起来可能令人难以置信,但我无法完成这项工作。
import re
import requests
from bs4 import BeautifulSoup
token_poo = requests.get("https://poocoin.app/tokens/0x3d29aa78fb558f84112bbc48a84f371147a920c9")
soupb = BeautifulSoup(token_poo.content, 'html.parser')
#print price
price = soupb.find_all('div', class_='mb-1 d-flex flex-column lh-1')
pricebox = price.find('span', class_='text-success').get_text()
#print("Price: " + (pricebox).strip())
print(pricebox)
在使用 find(id=) 时它适用于 bscScan,但 bscScan 价格通常无用。 希望不要太愚蠢的问题, 提前非常感谢
【问题讨论】:
-
您遇到了什么错误?我使用 Javascript 手动尝试了同样的事情,它似乎有效。
-
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?是一个。当我遵循建议时,它会抛出AttributeError: 'NoneType' object has no attribute 'find'我已经阅读了这些内容并稍微移动了代码但无法修复它......你扩展了这个想法了吗? -
运行代码,价格变量是一个空列表。你得到的第一个错误可能是查看列表并建议你只使用其中的一个元素,即使它是空的。所以你的 find_all 没有找到任何匹配项
-
有道理,是的。感谢您的澄清!
标签: python html web-scraping