Coinmarketcap 网络抓取 BCoin 价格
Coinmarketcap webscraping BCoin price
我正在尝试获取 coinmarketcap 加密货币的价格。不幸的是它不起作用。有人可以帮忙吗?
我想显示这个币的价格:https://coinmarketcap.com/currencies/bombcrypto/
我的代码:
#!/usr/bin/env python3
from bs4 import BeautifulSoup as S
import requests
c = input('bombcrypto')
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_='sc-16r8icm-0 kjciSH priceTitle').text
print(x)
谢谢
您的代码有几个问题。在通过元素查找路径时,请确保正确遵循网页的结构。我还更改了第 5 行的输入语句。
#!/usr/bin/env python3
from bs4 import BeautifulSoup as S
import requests
c = input("Crypto: ")#'bombcrypto'
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_='sc-16r8icm-0 kjciSH priceTitle').findChild(class_="priceValue").findChild('span')
print(x.text)
我正在尝试获取 coinmarketcap 加密货币的价格。不幸的是它不起作用。有人可以帮忙吗?
我想显示这个币的价格:https://coinmarketcap.com/currencies/bombcrypto/
我的代码:
#!/usr/bin/env python3
from bs4 import BeautifulSoup as S
import requests
c = input('bombcrypto')
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_='sc-16r8icm-0 kjciSH priceTitle').text
print(x)
谢谢
您的代码有几个问题。在通过元素查找路径时,请确保正确遵循网页的结构。我还更改了第 5 行的输入语句。
#!/usr/bin/env python3
from bs4 import BeautifulSoup as S
import requests
c = input("Crypto: ")#'bombcrypto'
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_='sc-16r8icm-0 kjciSH priceTitle').findChild(class_="priceValue").findChild('span')
print(x.text)