我使用 python bs4/selenium 来抓取网页。我对抓取此页面感兴趣。如您所见,有几个 js 图表。但是当我查看源代码时,我没有找到点的值。我怎样才能刮掉这些值。
问问题
400 次
1 回答
0
那是在 javascript 元素中<script type="a1b007d447753b98178810e9-text/javascript">
在某些时候,您会发现类似
new Chart(document.querySelector("#daily_data").getContext('2d'), {
type: 'line',
data: {
labels: [1583107200000,1583193600000,1583280000000,1583366400000,1583452800000,1583539200000,1583625600000,1583712000000,1583798400000,1583884800000,1583971200000,1584057600000,1584144000000,1584230400000,1584316800000,1584403200000,1584489600000,1584576000000,1584662400000,1584748800000,1584835200000,1584921600000,1585008000000,1585094400000,1585180800000,1585267200000,1585353600000,1585440000000,1585526400000,1585612800000,1585699200000,1585785600000,1585872000000,1585958400000,1586044800000,1586131200000,1586217600000,1586304000000,1586390400000,1586476800000,1586563200000,1586649600000,1586736000000,1586822400000,1586908800000,1586995200000,1587081600000,1587168000000,1587254400000,1587340800000,1587427200000,1587513600000,1587600000000,1587686400000,1587772800000,1587859200000,1587945600000,1588032000000,1588118400000,1588204800000,1588291200000,1588377600000,1588464000000,1588550400000,1588636800000,1588723200000,1588809600000,1588896000000,1588982400000,1589068800000,1589155200000,1589241600000,1589328000000,1589414400000,1589500800000,1589587200000,1589673600000,1589760000000],
datasets: [{
label: labels.cases,
backgroundColor: '#ffa800',
borderColor: '#ffa800',
data: [1,0,1,0,0,0,0,1,0,3,0,2,10,10,9,7,10,9,16,17,19,28,27,55,50,70,57,77,77,61,37,54,83,128,102,99,64,91,99,74,97,116,102,125,136,259,281,121,170,191,163,237,122,190,139,168,55,132,69,102,146,160,174,150,166,189,140,163,199,153,218,137,94,95,45,89,129,82] }, {
label: labels.recovered,
backgroundColor: '#18d26b',
borderColor: '#18d26b',
data: [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,2,1,1,1,3,1,1,2,9,5,2,26,9,10,5,12,4,12,13,24,31,26,14,12,20,32,33,13,23,43,24,39,30,51,56,102,83,150,56,99,173,182,215,185,179,162,145,137,93,257,180,140,179,90,87,173,98] }, {
label: labels.deaths,
backgroundColor: '#ff3f3f',
borderColor: '#ff3f3f',
data: [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,0,1,0,1,1,4,13,2,1,7,3,3,5,4,11,11,10,10,3,4,10,4,7,8,0,1,3,5,2,4,2,2,4,6,3,1,2,1,3,3,2,1,2,1,5,2,2,0,3,0,2,0,0,0,2,0,2,0,0] }]
},
这些是您的数据点。页面上的每个图表都有一个 Chart 对象。
因此,您现在可以考虑阅读帖子https://stackoverflow.com/a/26440563/1328968
于 2020-05-18T18:50:46.013 回答