我正在尝试Cases从 获取 COVID-19 阳性病例列表https://www.worldometers.info/,例如这个示例如下(~行号:700):<script type="text/javascript"> Highcharts.chart('coronavirus-cases-linear', { chart: { type: 'line' }, title: { text: 'Total Cases' }, subtitle: { text: '(Linear Scale)' }, xAxis: { categories: ["Feb 15","Feb 16","Feb 17","Feb 18","Feb 19","Feb 20","Feb 21","Feb 22","Feb 23","Feb 24","Feb 25","Feb 26","Feb 27","Feb 28","Feb 29","Mar 01","Mar 02","Mar 03","Mar 04","Mar 05","Mar 06","Mar 07","Mar 08","Mar 09","Mar 10","Mar 11","Mar 12","Mar 13","Mar 14","Mar 15","Mar 16","Mar 17","Mar 18","Mar 19","Mar 20","Mar 21","Mar 22","Mar 23","Mar 24","Mar 25","Mar 26","Mar 27","Mar 28","Mar 29","Mar 30","Mar 31","Apr 01","Apr 02","Apr 03","Apr 04","Apr 05","Apr 06","Apr 07","Apr 08","Apr 09","Apr 10","Apr 11"] }, yAxis: { title: { text: 'Total Coronavirus Cases' } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'middle' }, credits: { enabled: false }, series: [{ name: 'Cases', color: '#33CCFF', lineWidth: 5, ## I NEED THIS LIST responsive: { rules: [{ condition: { maxWidth: 800 }, chartOptions: { legend: { layout: 'horizontal', align: 'center', verticalAlign: 'bottom' } } }] } });它确实会抓取文件,但之后我不知道如何获取数据。我正在寻找的列表带有注释## I NEED THIS LIST。请帮忙。
1 回答
aluckdog
TA贡献1847条经验 获得超7个赞
你可以为它写一个正则表达式
import requests as req
import re
resp = req.get("https://www.worldometers.info/coronavirus/country/spain/")
p = re.compile(r"(?<=name:\s'Cases')[\s\S]+?data:\s(\[.*?\])")
p.findall(resp.text)[0]
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报
0/150
提交
取消