You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python爬虫抓取Poocoin页面动态数据返回错误值及None问题

问题根因
  • 你选取的px-3类div包含了总供应量、市值、LP持仓等一整段关联内容,没有做字段拆分所以会输出大量冗余信息
  • 你选取的text-success类span对应的是代币当前单价,不是市值数值,所以返回的是错误的价格数据
修正后代码
import time, re
from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome('chromedriver.exe')
url = "https://poocoin.app/tokens/0xb081cbaaa86959fc4033fde02bc539c4e897f0a1"
driver.get(url)
time.sleep(8)

soup = BeautifulSoup(driver.page_source, 'lxml')
# 先拿到包含目标字段的大段文本
content = soup.find('div', class_='px-3').text

# 正则匹配提取总供应量
ts_res = re.search(r'Total Supply:([\d,]+)', content)
# 正则匹配提取市值
mc_res = re.search(r'Market Cap: \(Includes locked, excludes burned\)(\$[\d,]+)', content)

# 按期望格式输出
if ts_res:
    print("Total Supply:")
    print(ts_res.group(1))
print()
if mc_res:
    print("Market Cap: (Includes locked, excludes burned)")
    print(mc_res.group(1))

driver.quit()
改动说明
  • 新增正则匹配逻辑,从大段文本中精准过滤出两个目标字段,完全剔除冗余内容
  • 修正了市值字段的抓取规则,不再误取价格数据,返回值和页面实际展示的市值一致
  • 输出格式完全匹配预期要求

内容的提问来源于stack exchange,提问作者rbutrnz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 18:18:03