我需要从这个图表中抓取数据,但是是表格格式.Link个
问题是这个图表的 struct ,因为它有几个月的年中,我try 了一些在线刮板,但他们消耗太多的时间,有时我得到扭曲的数据.
更详细地说,我正在使用这个软件,我引用这个软件是因为它可以帮助其他像我一样的人
你建议我怎么做才能得到最好的结果,因为我需要刮掉很多这样的图表
请告诉我,我是新来的,礼貌一点,如果我必须编辑这个问题,请告诉我
我需要从这个图表中抓取数据,但是是表格格式.Link个
问题是这个图表的 struct ,因为它有几个月的年中,我try 了一些在线刮板,但他们消耗太多的时间,有时我得到扭曲的数据.
更详细地说,我正在使用这个软件,我引用这个软件是因为它可以帮助其他像我一样的人
你建议我怎么做才能得到最好的结果,因为我需要刮掉很多这样的图表
请告诉我,我是新来的,礼貌一点,如果我必须编辑这个问题,请告诉我
GRAPH的数据嵌入在<script>
个标记中,因此可以使用下面的示例获取它们:
import json
import re
import pandas as pd
import requests
url = "https://www.instat.gov.al/en/sdgs/no-poverty/12-by-2030-reduce-at-least-by-half-the-proportion-of-men-women-and-children-of-all-ages-living-in-poverty-in-all-its-dimensions-according-to-national-definitions/121-proportion-of-population-living-below-the-national-poverty-line-by-sex-and-age/"
html_text = requests.get(url).text
# for map data:
# map_data = re.search(r"mapData=(.*?);<", html_text).group(1)
# print(map_data)
graph_data = re.search(r"graphsDataJson=(.*?);<", html_text).group(1)
graph_data = json.loads(graph_data)
df = pd.DataFrame(graph_data[0]["indicatorDataValues"])
print(df)
打印:
year value
0 2017 23.7
1 2018 23.4
2 2019 23.0
3 2020 21.8