用 Python 抓取 BTC 价格

时间:2021-04-11 17:14:46

标签: python web-scraping

我目前正在尝试使用 Python 从网站上抓取比特币的价格。但是,该函数返回“无”,我不确定为什么。

代码:

from bs4 import BeautifulSoup
import urllib.request 
import re 

def scraper():

    r = urllib.request.urlopen("https://www.kitco.com/bitcoin-price-charts-usd/").read()
    
    soup = BeautifulSoup(r, 'html.parser')

    btcPrice = soup.find('div', class_= 'tv-widget-watch-list__last js-symbol-last apply-overflow-tooltip')

    return btcPrice

def main():

    print(f"{scraper()}")

main()

输出:

None

我认为这个问题可能与html解析器有关,或者只是对我需要的信息使用了错误的标签。任何帮助,将不胜感激。提前致谢。

0 个答案:

没有答案