To unpack a zip file from url request

To unpack a zip file from url request



I want to get this XML file from a danish website with the URL https://www.foedevarestyrelsen.dk/_layouts/15/sdata/smileystatus.zip, but the data comes in a zip file. This is problematic because I want to get the data sheet directly into Python for a school project, and not to save it local and convert it into csv. So far I have tried following codes inspired from answers to previous questions about this subject....


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)



and I have also tried:


from zipfile import ZipFile
import requests
import pandas as pd

url = 'https://www.foedevarestyrelsen.dk/_layouts/15/sdata/smileystatus.zip'
df = pd.read_csv(url,
compression = "zip")





extracted_file = zipfile.open("SmileyStatus.xls") are you sure it is not SmileyStatus.zip?
– E.Serra
Aug 24 at 13:50





So from a cursory look, ZipFile(BytesIO(url.content) should be what you want. That all looks right. What goes wrong? What errors do you get? Do you get them if you manually download and unzip and just do pd.read_excel('path/to/you/manually/unzipped/SmileyStatus.xls') (Your second method definitely won't work because a zip file is not a csv, nor is an xls)
– Bailey Parker
Aug 24 at 13:51


ZipFile(BytesIO(url.content)


pd.read_excel('path/to/you/manually/unzipped/SmileyStatus.xls')





First of all, it is a xls file, so I gave you the wrong information. Sorry! I get this error message when running my first code: CompDocError: Workbook: size exceeds expected 27286528 bytes; corrupt?
– Helene Østergaard
Aug 24 at 14:20










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế