我在这个平台上主要是一个潜伏者,并试图使用已经提出的问题的答案来解决我的问题,但我找不到我当前问题的答案。我试图从这个website网站使用scrapy刮数据。我已经能够刮大部分的数据,我需要然而,有两个互动的高点图表,我想有数据。Picture of first graph
到目前为止,我尝试了:
- 直接从html响应中提取数据,但我只能访问轴值,因此this方法不起作用。
- 通过在浏览器中使用dev Tools查找API调用来提取数据,类似于this方法。然而,唯一可见的XHR被称为 footprint,并且不包含任何响应。在 footproint 的initiator选项卡中有一个指向https://crowdcircus.com/js/app.js?id=6677107ebf6c7824be09的Request调用堆栈,但我不知道这是否有帮助,因为我对json和webscraping真的很陌生。
一个提示和/或解释如何从这个网站刮这个图表数据将不胜感激。
要查看图表,您必须登录here。我已经创建了一个一次性帐户:邮箱:[[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection)
,密码:12345
这样你就可以看到数据了。
更新:
我的回答为我指明了正确的方向。我最终使用了scarpy_splash
,它允许用lua执行JavaScript代码。有了下面的代码,我就能收集到我需要的所有数据。
LUA_SCRIPT = """
function main(splash)
-- Get cookies from previous session
splash:init_cookies(splash.args.cookies)
assert(splash:go(splash.args.url))
assert(splash:wait(0.5))
-- Extract data from page
-- Read amount of variables in second table
table_2_no_series = splash:evaljs('Highcharts.charts[1].series.length')
-- If second table has more variable then one, get this data aswell
if (table_2_no_series==2) or (table_2_no_series==3) then
table_2_y1_data = splash:evaljs('Highcharts.charts[1].series[0].yData')
table_2_y1_name = splash:evaljs('Highcharts.charts[1].series[0].name')
end
if (table_2_no_series==3) then
table_2_y3_data = splash:evaljs('Highcharts.charts[1].series[2].yData')
table_2_y3_name = splash:evaljs('Highcharts.charts[1].series[2].name')
end
return {
-- Extract webiste title
title = splash:evaljs('document.title'),
-- Extract first table data
table_1_name = splash:evaljs('Highcharts.charts[0].title.textStr'),
-- Extract Timestamps
table_1_x = splash:evaljs('Highcharts.charts[0].series[0].xAxis.categories'),
-- Extract Finanzierungsstand
table_1_y_data = splash:evaljs('Highcharts.charts[0].series[1].yData'),
table_1_y_name = splash:evaljs('Highcharts.charts[0].title.textStr'),
-- Extract second table data
table_2_y1_data,
table_2_y1_name,
table_2_y3_data,
table_2_y3_name,
cookies = splash:get_cookies(),
}
end
"""
SCRAPY_ARGS = {
'lua_source': LUA_SCRIPT,
'cookies' : self.cookies
}
# Look for json data if we sucessfully logged in
yield SplashRequest(url=response.url,
callback=self.parse_highchart_data,
endpoint='execute', args=SCRAPY_ARGS,
session_id="foo")
注意:highchart API也有一个.getCSV
,可以导出csv格式的数据。但是,这个网站似乎阻止了这个功能。
2条答案
按热度按时间pn9klfpd1#
这并不是一种完全的抓取方法,但是从Highcharts站点,你可以使用Web控制台工具看到整个图表配置。尝试用途:
console.log(Highcharts.charts)
,显示页面上呈现的图表数组。接下来,转到特定图表->系列->数据,例如:console.log(Highcharts.charts[0].series[1].data)
oyxsuwqo2#
这对我很有效:console.log(Highcharts.charts[1].series[0].processedYData)