首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >试图刮掉市场份额,得到“零”

试图刮掉市场份额,得到“零”
EN

Stack Overflow用户
提问于 2021-07-01 14:18:14
回答 1查看 98关注 0票数 0

我用python构建了一个基本脚本,用于、coinmarketcap帽中的一些数据,但我没有得到,我也不知道为什么,你能帮我吗?

代码语言:javascript
复制
from bs4 import BeautifulSoup as S
import requests

c = input('enter your coin')
url = f'https://coinmarketcap.com/currencies/{c}/'

headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}

r = requests.get(url,headers=headers)

soup = S(r.content,'html.parser')

print(f'the price of {c} now is ')
x = soup.find(id="priceValue___11gHJ")
print(x)```
EN

回答 1

Stack Overflow用户

发布于 2021-07-01 14:58:14

我已经测试了您的代码,并进行了一些更改以使其工作。

要获得的字段使用类而不是id。

看一看。

代码语言:javascript
复制
#!/usr/bin/env python3
from bs4 import BeautifulSoup as S
import requests

c = input('enter your coin')
url = f'https://coinmarketcap.com/currencies/{c}/'

headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}

r = requests.get(url,headers=headers)
soup = S(r.content,'html.parser')
print(f'the price of {c} now is ')
x = soup.find(class_='priceValue___11gHJ').text
print(x)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68211892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档