我对Python比较陌生,所以如果这是布什联盟的问题,我会道歉。
我试图从本网站检索WTI期货价格: https://www.cmegroup.com/trading/energy/crude-oil/west-texas-intermediate-wti-crude-oil-calendar-swap-futures_quotes_globex.html
我应该使用哪些库?当输出从网站上拉出来时,我需要如何调整?
目前使用Python3.6.8操作熊猫、numpy、requests、URLLB3、Beautiulsoup和json库。我不确定这些库是否正确,以及它们是否是我应该使用的函数。
以下是代码的基本版本:
wtiFutC = 'https://www.cmegroup.com/trading/energy/crude-oil/west-texas-intermediate-wti-crude-oil-calendar-swap-futures_quotes_globex.html'
http = urllib3.PoolManager()
response2 = http.request('GET', wtiFutC)
print(type(response2.data)) #check the type of the data produced - bytes
print(response2.data) #prints out the data
soup2 = BeautifulSoup(response2.data.decode('utf-8'), features='html.parser')
print(type(soup2)) #check the type of the data produced - 'bs4.BeautifulSoup'
print(soup2) #prints out the BeautifulSoup version of the data
我想找一个方法来看看WTI未来的最后一个价格。相反,我看到的是这样的东西:
^{pr2}$如有任何帮助或指示,将不胜感激。非常感谢!:)
使用页面所做的端点并从json解析出感兴趣的列(和日期)
该网页中的数据是javascript生成的,因此很难用
requests
之类的包提取数据。 如果这不是什么大问题,我建议您寻找一个使用最少或不使用javascript的不同数据源。然后使用requests
获取网页源并从中提取数据。在您可以使用}之类的库中,如果您想对数据进行分析和计算的话。在
BeautifulSoup
或re
(在某些情况下甚至是pandas
)之类的库提取数据,并将它们馈送到numpy
或{否则,我建议您看看
Selenium
以获得javascript支持。在使用Requests-HTML。如果你已经熟悉了请求,这是一个很好的资源。在
相关问题 更多 >
编程相关推荐