我想从丹麦的网站上获得URL为https://www.foedevarestyrelsen.dk/_layouts/15/sdata/smileystatus.zip的XML文件,但是数据来自一个zip文件。这是有问题的,因为我想将数据表直接获取到学校项目的Python中,而不是将其保存在本地并将其转换为csv。到目前为止,我已经尝试遵循受此问题以前的答案启发而编写的代码。
class myouterclass(object):
def __init__(self, the_id):
self.myouterclassID = the_id
self.myinnerclass = self.MYINNERCLASS(the_id)
class MYINNERCLASS:
def __init__(self, inner_id):
self.myinnerclassID = inner_id
def __init__(self, inner_id):
self.myinnerclassID = inner_id
我也尝试过:
from zipfile import ZipFile
from io import BytesIO
import requests
import pandas as pd
def get_zip(file_url):
url = requests.get(file_url)
zipfile = ZipFile(BytesIO(url.content))
zip_names = zipfile.namelist()
if len(zip_names) == 1:
SmileyStatus = zip_names.pop()
extracted_file = zipfile.open("SmileyStatus.xls")
return extracted_file
xls = get_zip("https://www.foedevarestyrelsen.dk/_layouts/15/sdata/smileystatus.zip")
data = pd.read_excel(xls)