python 网络数据采集——媒体文件
2016-09-29 23:23
495 查看
声名:本文为学习笔记,内容来自于《python 网络数据采集》(英文名:Web Scraping with Python)
存储媒体文件有两种主要方式:只获取URL链接,或者直接把源文件下载下来。如果,文件需要多次使用,那么最好下载下来。以下载图片为例,在Python 3.x 版本中,urllib.request.urlretrieve可以根据文件的URL下载文件:
from urllib.request import urlretrieve from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("http://www.pythonscraping.com") bsObj = BeautifulSoup(html) imageLocation = bsObj.find("a", {"id": "logo"}).find("img")["src"] urlretrieve(imageLocation, "logo.jpg")
这段程序是从http://pythonscraping.com下载logo图片,然后在程序运行的文件夹里保存为logo.jpg文件。
相关文章推荐
- python网络数据采集-如何实现文件上传
- Python网络数据采集1(译者:哈雷)
- Python网络数据采集9(译者:哈雷)
- python网络数据采集学习笔记:第二章
- python网络数据采集的代码
- 笔记之Python网络数据采集
- 笔记之Python网络数据采集
- Python网络数据采集10(译者:哈雷)
- python网络数据采集
- Python网络数据采集一书中的错误
- python网络数据采集学习笔记-前言
- python网络数据采集2(译者:哈雷)
- Python网络数据采集4(译者:哈雷)
- 20161229:for python网络数据采集03
- python 网络数据采集(1-5章)
- Python网络数据采集5(译者:哈雷)
- Python网络数据采集
- Python网络数据采集7(译者:哈雷)
- 好书推荐:Python网络数据采集
- Python网络数据采集Urllib库的基本使用