我想从html获取所有属性的列表。我有以下代码:
fhand = urllib.request.urlopen("http://www.coinmarketcap.com")
for line in fhand:
print(line.decode().strip())
soup = BeautifulSoup(fhand, 'html.parser')
verificar = soup.find_all("a", class_="price-toggle")
print(verificar)
我得到的只是[]
,我想得到:[BTC,ETH ....]
。所有的价格都在这里:
<li class="pointer"><a class="price-toggle" data-currency="xrp" data-currencyid="ripple">**XRP**</a></li>
韩国社交协会
答案 0 :(得分:1)
尝试使用以下代码获取所需的输出:
import requests
from bs4 import BeautifulSoup
fhand = requests.get("http://www.coinmarketcap.com").text
soup = BeautifulSoup(fhand, 'html.parser')
verificar = soup.find_all("a", class_="price-toggle")
for item in verificar:
print(item.text)
输出:
'USD'
'USD'
'BTC'
'ETH'
'XRP'
'BCH'
'LTC'