问题描述
我正在尝试将一些能源数据导入Google表格,但似乎无法显示该值,因为它只是HTML行中的文本,并在-,---中显示为输出。我曾尝试将/ text()添加到XPath中,但这仍然无法正常工作。
要导入数据的网站:
http://www.caiso.com/TodaysOutlook/Pages/default.aspx
Google表格中的公式:
=IMPORTXML("http://www.caiso.com/TodaysOutlook/Pages/default.aspx","//div[@class='overview-large-number']")
还尝试了以下Xpath并显示相同的-,---。
/html/body/div[2]/div[3]/div[4]/div/div/div[2]/div/div[1]/div[1]/div[1]
/html/body/div[2]/div[3]/div[4]/div/div/div[2]/div/div[1]/div[1]/div[1]/text()
网页的屏幕截图:
带有数据的HTML元素:
<div class="overview-large-number">41,946 <span>MW</span></div>
Google表格当前输出的屏幕快照:
非常感谢您提供任何见识。
解决方法
页面加载后将填充数据,因此您不能使用ImportXML()
。通过URL http://www.caiso.com/outlook/SP/stats.txt
上的HTTP Get请求数据,并以JSON格式返回。
- 从here获取ImportJSON脚本并将其添加到工作表中(工具>脚本编辑器)。
- 这应该足以让您入门:
=Transpose(ArrayFormula(HLOOKUP(
{"AvailableCapacity","CurrentSystemDemand","todayForecastPeakDemand","histDemand","TodaysPeakDemand","tomorrowsForecastPeakDemand"},ImportJSON("http://www.caiso.com/outlook/SP/stats.txt"),2,0)))
请注意,“历史峰值”已经是一个字符串,因此您可能需要做一些额外的工作才能得出该数字。