import urllib.request
import requests
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ‘
‘Chrome/96.0.4664.110 Safari/537.36 ‘
}

url = ‘https://www.1ppt.com/moban/
req = urllib.request.Request(url, headers=headers)
res = urllib.request.urlopen(req)
html = res.read().decode(‘gb2312’)
# print(html)
with open(‘第一次作业.html’, ‘w’, encoding=’utf-8’) as f:
f.write(html)

# 使用urllib
# url = ‘https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.puchedu.cn%2Fuploads%2F0%2F26%2F3211794671‘ \
# ‘%2F2156152069.jpg&refer=http%3A%2F%2Fimg.puchedu.cn&app=2002&size=f9999,’ \
# ‘10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643898235&t=9b82b5ae235b072d56c2cd808afb487e ‘
# # urllib.request.urlretrieve(url, ‘梅西.png’)
# req = urllib.request.Request(url)
# res = urllib.request.urlopen(req)
# with open(‘梅西.png’, ‘wb’) as f:
# f.write(res.read())

# 使用requests库
# url = ‘https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.puchedu.cn%2Fuploads%2F0%2F26%2F3211794671‘ \
# ‘%2F2156152069.jpg&refer=http%3A%2F%2Fimg.puchedu.cn&app=2002&size=f9999,’ \
# ‘10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643898235&t=9b82b5ae235b072d56c2cd808afb487e ‘
# req = requests.get(url)
# res = req.content
# with open(‘梅西.png’, ‘wb’) as f:
# f.write(res)