Saturday, July 3, 2021

【PYTHON】urllib basics

 # urllib basics


from urllib.request import urlopen


url = 'https://en.wikipedia.org/wiki/General-purpose_programming_language'

page = urlopen(url).read()


page[:50]


page[:50].decode('utf-8')


page[-100:]


from bs4 import UnicodeDammit


suggestion = UnicodeDammit(page)

suggestion.original_encoding


datafile_url = 'https://docs.misoenergy.org/marketreports/20210203_mom.xlsx'

mom_data = urlopen(datafile_url).read()

mom_data[:20]


import pandas as pd

df = pd.read_excel(mom_data)

df.head()


df = pd.read_excel(datafile_url)

df.head()


df.to_excel('mom_report.xlsx')


with open('mom_report.xlsx', 'wb') as f:

    f.write(mom_data)


from urllib.request import urlretrieve


urlretrieve(datafile_url, 'mom_report.xlsx')


df = pd.read_excel('mom_report.xlsx')

df.head()

No comments:

Post a Comment

End of Summer Sale ☀️😎

20% OFF Inside!🤯 ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏...