我想从像this (stat game of the game I play)这样的站点抓取数据,其中交互式图表在<canvas>
元素中呈现,并且没有将任何数据显示为可抓取的HTML元素。检查HTML,页面似乎使用chartjs。
虽然python中的帮助是首选,但如果我真的需要使用一些javascript,那也没问题。
另外,我希望避免使用需要额外文件的方法,如phantomjs,但如果这是唯一的方法,请慷慨地分享它。
我想从像this (stat game of the game I play)这样的站点抓取数据,其中交互式图表在<canvas>
元素中呈现,并且没有将任何数据显示为可抓取的HTML元素。检查HTML,页面似乎使用chartjs。
虽然python中的帮助是首选,但如果我真的需要使用一些javascript,那也没问题。
另外,我希望避免使用需要额外文件的方法,如phantomjs,但如果这是唯一的方法,请慷慨地分享它。
1条答案
按热度按时间fae0ux8s1#
解决这个问题的一种方法是在页面源代码中第1050行附近检查页面的
<script>
,这实际上是图表初始化的地方。在图表的初始化过程中有一个循环模式,其中画布元素被逐个查询以获得它们的上下文,然后是提供图表的标签和统计信息的变量。此解决方案包括使用node.js,至少是包含以下模块的最新版本:
下面是solution和源代码: