Python 从奇怪的仪表板格式中删除数据

Python 从奇怪的仪表板格式中删除数据,python,web-scraping,beautifulsoup,lxml,Python,Web Scraping,Beautifulsoup,Lxml,我正在收集新冠病毒疫苗接种数据,我正在尝试使用Python从这个网站上删除疫苗编号(第一个--“接受1剂疫苗的人”)。我尝试使用BeautifulSoup来提取HTML,然后通过XPath或属性进行搜索。当然,首先,我使用BeautifulSoup解析页面: rhode_island = BeautifulSoup(requests.get('https://ri-department-of-health-covid-19-data-rihealth.hub.arcgis.com').conte

我正在收集新冠病毒疫苗接种数据,我正在尝试使用Python从这个网站上删除疫苗编号(第一个--“接受1剂疫苗的人”)。我尝试使用BeautifulSoup来提取HTML,然后通过XPath或属性进行搜索。当然,首先,我使用BeautifulSoup解析页面:

rhode_island = BeautifulSoup(requests.get('https://ri-department-of-health-covid-19-data-rihealth.hub.arcgis.com').content, 'html.parser')
但这个HTML输出看起来与页面上的实际HTML完全不同——相反,它只是一行接一行的类似内容:

%22%5D%7D%2C%22validationClasses%22%3A%7B%22fieldSuccess%22%3A%5B%22field-success%22%5D%2C%22fieldError%22%3A%5B%22field-error%22%5D%2C%22controlSuccess%22%3A%5B%22control-success%22%5D%2C%
我不确定这里到底发生了什么——我尝试了几种不同的方法(LXML,BeautifulSoup),但都返回了这个奇怪的结果。因此,我无法刮出我正在寻找的信息,因为它似乎不是真正的HTML(我已经尝试过,但刮出失败)


有人知道我能做些什么来刮取这些数据吗?

该页面使用大量Javascript,需要一个浏览器来正确呈现数据,并且正在使用ArcGIS REST API

在浏览器中加载类似的页面,或者查看他们从何处获取数据-在这种情况下,似乎是一个
COVID\u Public\u Map\u TEST
数据集,您可以查询:

In [1]: import requests

In [2]: session = requests.Session()

In [3]: session.headers = {'Accept': '*/*', 'Content-Type': 'application/x-www-form-urlencoded'}

In [4] response = session.get('https://services1.arcgis.com/dkWT1XL4nglP5MLP/arcgis/rest/services/COVID_Public_Map_TEST/FeatureServer/2/query', params={'f': 'json', 'where': '1=1', 'returnGeometry': 'false', 'outFields': '*'})

In [5]: data = response.json()  

In [5]: data
Out[5]: 
{'objectIdFieldName': 'OBJECTID',
 'uniqueIdField': {'name': 'OBJECTID', 'isSystemMaintained': True},
 'globalIdFieldName': '',
 'fields': [{'name': 'OBJECTID',
   'type': 'esriFieldTypeOID',
   'alias': 'OBJECTID',
...
    'New_Covid_Fatality_Today': 23}},
  {'attributes': {'OBJECTID': 40,
    'City_Town': 'WOONSOCKET',
    'Count_of_COVID_19_Positive': 27,
    'Rate_per_1k': 0.00027,
    'Population_per': 99999,
    'Date': 1586304000000,
    'Covid_case': 77812,
    'Covid_Deaths': 1625,
    'Covid_Positive_Today': 395,
    'Total_Hospitalized': 459,
    'Covid_ICU': 56,
    'Covid_Ventilator': 29,
    'Total_Covid_Lab_Tests': 1817360,
    'Negative_Covid_Lab_Tests': 1723464,
    'New_Covid_Fatality_Today': 23}}]}
您可以通过
outStatistics
查询参数进行聚合


或者,更好的方法是,研究如何使用Python ArcGIS API以更方便的方式完成同样的工作。

该页面使用大量Javascript,需要浏览器正确呈现数据,并且正在使用ArcGIS REST API

在浏览器中加载类似的页面,或者查看他们从何处获取数据-在这种情况下,似乎是一个
COVID\u Public\u Map\u TEST
数据集,您可以查询:

In [1]: import requests

In [2]: session = requests.Session()

In [3]: session.headers = {'Accept': '*/*', 'Content-Type': 'application/x-www-form-urlencoded'}

In [4] response = session.get('https://services1.arcgis.com/dkWT1XL4nglP5MLP/arcgis/rest/services/COVID_Public_Map_TEST/FeatureServer/2/query', params={'f': 'json', 'where': '1=1', 'returnGeometry': 'false', 'outFields': '*'})

In [5]: data = response.json()  

In [5]: data
Out[5]: 
{'objectIdFieldName': 'OBJECTID',
 'uniqueIdField': {'name': 'OBJECTID', 'isSystemMaintained': True},
 'globalIdFieldName': '',
 'fields': [{'name': 'OBJECTID',
   'type': 'esriFieldTypeOID',
   'alias': 'OBJECTID',
...
    'New_Covid_Fatality_Today': 23}},
  {'attributes': {'OBJECTID': 40,
    'City_Town': 'WOONSOCKET',
    'Count_of_COVID_19_Positive': 27,
    'Rate_per_1k': 0.00027,
    'Population_per': 99999,
    'Date': 1586304000000,
    'Covid_case': 77812,
    'Covid_Deaths': 1625,
    'Covid_Positive_Today': 395,
    'Total_Hospitalized': 459,
    'Covid_ICU': 56,
    'Covid_Ventilator': 29,
    'Total_Covid_Lab_Tests': 1817360,
    'Negative_Covid_Lab_Tests': 1723464,
    'New_Covid_Fatality_Today': 23}}]}
您可以通过
outStatistics
查询参数进行聚合

或者,更好的方法是研究如何使用Python ArcGIS API以更方便的方式完成同样的工作