Web scraping 获取一组属性类型的列表

Web scraping 获取一组属性类型的列表,web-scraping,beautifulsoup,Web Scraping,Beautifulsoup,我想从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(verifi

我想从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>

Tks

尝试使用以下代码获得所需的输出:

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'

事实上,如果要删除for循环,我可以通过代码获得这些值,我认为这些没有任何意义lines@user1922364请注意,coinmarketcap.com有一个API,您可以在@Andersson How?@user1922364上找到它,只需注释掉fhand:printline.decode.strip中的行即可