解析python中的html输入元素

时间:2017-06-03 02:40:43

标签: python html parsing beautifulsoup

我正在尝试解析一个网站:https://www.cryptomkt.com/es/chile 我试图获得以太坊的价值,我认为源代码中的这一行由以下代码表示:

<input type="text" class="input-center" id="valor_eth" name="valor_eth" disabled="">

但我不能用漂亮的汤来做,因为这个数字并不是硬编码的。我是一个关于网页开发和编程爬虫的菜鸟,所以我很感激任何帮助。

1 个答案:

答案 0 :(得分:0)

价格是从json文件动态加载的。您可以从Web浏览器的开发人员工具中检查它。

所以你要做的就是解析那个json文件,并获得最新价格。

import urllib.request
import json
sourcefile = 'https://www.cryptomkt.com/api/ethclp/1440.json'
prices = json.loads(urllib.request.urlopen(sourcefile).read().decode('utf-8'))
low_price = prices['data']['prices_ask']['values'][0]['low_price']
print(low_price)