python爬取妹子图片2
来源:互联网 发布:免费com网站域名注册 编辑:程序博客网 时间:2024/05/09 09:47
这次是爬取妹子图片1的改良,代码变得更加简洁了,使用了requests库
#-*-coding:utf-8import requestsimport lxmlimport osfrom bs4 import BeautifulSoupclass MEZI(): def __init__(self,url,pageIndex): self.url=url+str(pageIndex) self.headers = {'User-Agent':'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} #得到一页的网页源码 def get_one_page_html(self): re=requests.get(self.url,headers=self.headers) html=re.text return html #得到一个妹子的写真集的url def get_one_person_url(self): all_a=[] html=self.get_one_page_html() soup=BeautifulSoup(html,'lxml') all_div=soup.find('div',class_='postlist') all_span=all_div.find('ul').find_all('span') for span in all_span: if span.find('a'): all_a.append(span.find('a').get('href')) return all_a def download(self,filename): #filename是你要存储的路径名 x=1 all_a=self.get_one_person_url() for a in all_a: #这里只是一张照片的地址 for i in range(1,30): #限制每个人下载30张照片 url=a+'/'+str(i) re=requests.get(url ,headers=self.headers) print u'正在下载图片:%s'%re.url html=re.text soup=BeautifulSoup(html,'lxml') img_url=soup.find('img').get('src') html_img = requests.get(img_url, headers=self.headers) img_name=str(x)+'.jpg' path=os.path.normpath(os.path.join(filename,img_name)) #这里是规范你的绝对路径,os.path.join(filename,img_name)是将目录名和文件名连接在一起 with open(path,'wb') as f: #开始下载 f.write(html_img.content) x=x+1if __name__=="__main__": url='http://www.mzitu.com/page/' for i in range(1,30): app = MEZI(url, i) filename = 'g:\\picture2' app.download(filename)
0 0
- python爬取妹子图片2
- Python实战(2)——爬取妹子图片
- python爬取妹子图片1
- Python爬取妹子网图片
- python 爬取煎蛋网妹子的图片
- Python爬虫之——爬取妹子图片
- Python 爬取妹子图
- python爬取妹子图
- python爬取妹子图
- 妹子图 Python 爬取
- 爬取素材网的妹子图片
- Python使用Scrapy爬取妹子图
- python爬取花瓣妹子信息
- 用BeautifulSoup爬取豆瓣妹子的图片
- python scrapy 爬取妹子图的照片
- python 爬取XX美图妹子照片
- 用python写爬虫,爬取清纯妹子网站
- [Python]网络爬虫学习笔记,爬取豆瓣妹子上妹子的照片
- 数独之Java实现
- 产生随机数
- 【37.50%】【codeforces 745B】Hongcow Solves A Puzzle
- lintcode(E)链表倒数第n个节点
- openMP学习心得
- python爬取妹子图片2
- 模拟搭建Web项目的真实运行环境(二)
- Hackademic Challenges教程
- 数塔
- logback 自定义
- java实现oracle和sqlserver数据库转换(包含大数据)
- 40. Combination Sum II
- 常用聚类算法(一) DBSCAN算法
- 提高Memcached缓存命中率