下载网页
- 首先引入
urllib.request
- 获取你要下载网页的url,比如
http://www.baidu.com
import urllib.request
#下载网页
url_page = 'http://www.baidu.com'
# urlretrieve参数:url代表的是下载的路径 filename文件的名字
urllib.request.urlretrieve(url_page,'baidu.html')
下载图片
- 同样引入urllib.request
- 获取网页上图片的位置
import urllib.request
url_img = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fvsd-picture.cdn.bcebos.com%2F6d24e80ad460b29998f68581ce3dce156724cc1a.jpg&refer=http%3A%2F%2Fvsd-picture.cdn.bcebos.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1638345094&t=d8fdf92397ebe663b5123b0ed84d1ed9'
urllib.request.urlretrieve(url_img,'tutu.jpg')
下载视频
- 获取视频资源的位置,与图片获取方法一样
import urllib.request
url_video = 'https://vd3.bdstatic.com/mda-kjtx64epufgk8zw5/sc/cae_h264_clips/1604104280/mda-kjtx64epufgk8zw5.mp4?auth_key=1635041016-0-0-ae78e8270156bdcde181b07135b8d135&bcevod_channel=searchbox_feed&pd=1&pt=3&abtest='
urllib.request.urlretrieve(url_video,'lisa.mp4')