python爬虫(3.下载文件)

来源:互联网 发布:js删除cookie 编辑:程序博客网 时间:2024/06/15 12:29

从网站下载图片,右键审查元素,找到
下载左边这个logo,右边是我们要用到的html标签

from urllib.request import  urlopenfrom urllib.request import  urlretrievefrom bs4 import BeautifulSoup html = urlopen("http://www.pythonscraping.com")bsObj=BeautifulSoup(html)urlLocation=bsObj.find("a",{"id":"logo"}).find("img")["src"]# urllib.request.urlretrieve 可以根据文件的 URL  下载文件#urlretrueve(location,file)  第一个参数是下载源第二个参数是保存的文件格式urlretrieve(urlLocation,"logo.jpg")
原创粉丝点击