【发布时间】:2018-03-09 11:15:24
【问题描述】:
我想用来自 coinmarketcap.com 的硬币建立一个列表。 每个元素都应该是一个元组。
类似:
coins = [('btc',8500,'+0.5%','+1.2%', '-1%'), ...]
我无法获得百分比:
信息在td 中是这样的:
<td class="no-wrap percent-change text-right positive_change" data-timespan="1h" data-percentusd="0.99" data-symbol="BTC" data-sort="0.991515">0.99%</td>
如何从上面获取 0.99% 的值?我实际上需要来自 td 的 data-percentageusd,但我不知道那是什么。
我的测试脚本是这样的:
import requests
from bs4 import BeautifulSoup
url = 'https://coinmarketcap.com/all/views/all/'
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
name = soup.find_all('a', class_='currency-name-container')
price = soup.find_all('a', class_='price')
print(name)
print(price)
#how can percentage modification for 1h, 24h, 7d?
#delta_h = soup.find_all('td', ???)
【问题讨论】:
标签: python web web-scraping beautifulsoup python-requests