Home > Mobile >  Extracting data from a UCI dataset Online using python if the file is compressed(.zip)
Extracting data from a UCI dataset Online using python if the file is compressed(.zip)

Time:02-21

I want to use web scrapping to get the data from file https://archive.ics.uci.edu/ml/machine-learning-databases/00380/YouTube-Spam-Collection-v1.zip

How can I do that using requests in python?

CodePudding user response:

You can use this example how to load the zip file using requests and built-in zipfile module:

import requests
from io import BytesIO
from zipfile import ZipFile


url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00380/YouTube-Spam-Collection-v1.zip"

with ZipFile(BytesIO(requests.get(url).content), "r") as myzip:
    # print content of zip:
    # print(myzip.namelist())

    # print content of one of the file:
    with myzip.open("Youtube01-Psy.csv", "r") as f_in:
        print(f_in.read())

Prints:

b'COMMENT_ID,AUTHOR,DATE,CONTENT,CLASS\n

...
  • Related