简体   繁体   中英

Unpack rar file from URL

I didn't find any answer on how to extract specific files from RAR (not Zip) from URL.

For example, I have this URL whith quite heavy rar: http://cbr.ru/vfs/credit/forms/101-20200401.rar

What is the best way to take file from this RAR without downloading it to the disk?

Thanks

I tried many Python Libraries, but I finally found the solution using rarfile

1- install rarfile

2- use the following:

import urllib
import rarfile
from io import BytesIO

resp = urllib.request.urlopen('http://cbr.ru/vfs/credit/forms/101-20200401.rar')
r = rarfile.RarFile(BytesIO(resp.read()))
r.namelist()

The output will be:

['032020N1.DBF', 'NAMES.DBF', '032020B1.DBF']
  1. To open file you should use r.open()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM