(1)获取百度网页并打印
#encoding:utf-8
import requests
url='http://www.baidu.com'
r=requests.get(url)
r.encoding=r.apparent_encoding
print(r.text)
运行结果:
比如说我现在想把这张图片下载下来:
import requests
s='https://imgs.qunarzz.com/p/p67/1512/a2/0ebfcd965b9391f7.jpg_255x175_06112aad.jpg'
r=requests.get(s)
with open('0ebfcd965b9391f7.jpg','wb') as f:
f.write(r.content)
print('下载完成')
运行结果: