使用python获取火币网的btc数据(未完成)


方法:使用python与xpath,提取span.price里的数据

场景:可以定时运行,每隔五分钟在屏幕上打印一次btc的实时价位,把握好时机被噶韭菜。

xpath:在chrome里的f12里的console输入$x("//a[@href='/zh-cn/exchange/btc_usdt/']/span[@class='price']/text()")[0],可以得到btc的实时数据

代码如下:

import requests
from lxml import etree

url = 'https://www.huobi.me/zh-cn/exchange/btc_usdt/'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
}

page_text = requests.get(url=url, headers=headers).text
tree = etree.HTML(page_text)
pricebtc = tree.xpath("//a[@href='/zh-cn/exchange/btc_usdt/']/span[@class='price']/text()")
print(pricebtc)
~                   

但是运行后的结果是[],不知道是什么原因?有没有大神能帮忙解读一下?


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM