爬虫案例——淘宝图片爬虫
2018-03-25 20:09
531 查看
在淘宝网中搜索某种商品之后会跳转到新的网页,网页的底部有可以进行换页,爬虫之前我们需要找出不同页码之间是否存在某种规律。
https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306 https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s=44 https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s=88 可以发现,第一页的url中是没有s=?的,从第二页开始s=44,第三页s=88,找到规律之后可以通过循环进行跨页爬取了import urllib.request
import re
keyname='短裙'
keyname=urllib.request.quote(keyname)
headers=('User-Agent',"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
for i in range(0,2):
url='https://s.taobao.com/search?q='+keyname+'&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s='+str(i*44)
data=urllib.request.urlopen(url).read().decode('utf-8','ignore')
pat='pic_url":"//(.*?)"'
imagelist=re.compile(pat).findall(data)
for j in range(0,len(imagelist)):
thisimage=imagelist[j]
thisurl='http://'+thisimage
file='D:/1python/淘宝/'+str(i)+str(j)+'.jpg'
urllib.request.urlretrieve(thisurl,file)
https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306 https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s=44 https://s.taobao.com/search?q=%E7%9F%AD%E8%A3%99&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s=88 可以发现,第一页的url中是没有s=?的,从第二页开始s=44,第三页s=88,找到规律之后可以通过循环进行跨页爬取了import urllib.request
import re
keyname='短裙'
keyname=urllib.request.quote(keyname)
headers=('User-Agent',"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
for i in range(0,2):
url='https://s.taobao.com/search?q='+keyname+'&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s='+str(i*44)
data=urllib.request.urlopen(url).read().decode('utf-8','ignore')
pat='pic_url":"//(.*?)"'
imagelist=re.compile(pat).findall(data)
for j in range(0,len(imagelist)):
thisimage=imagelist[j]
thisurl='http://'+thisimage
file='D:/1python/淘宝/'+str(i)+str(j)+'.jpg'
urllib.request.urlretrieve(thisurl,file)
相关文章推荐
- 爬虫案例若干-爬取CSDN博文,糗事百科段子以及淘宝的图片
- 简单的抓取淘宝图片的Python爬虫
- 【Scrapy-02】图片网站的爬虫开发技巧和案例
- (案例四)图片下载器爬虫
- python学习(4):python爬虫入门案例-爬取图片
- python网络爬虫学习(六)利用Pyspider+Phantomjs爬取淘宝模特图片
- Python爬虫(入门+进阶)学习笔记 1-8 使用自动化神器Selenium爬取动态网页(案例三:爬取淘宝商品)
- 简单的抓取淘宝关键字信息、图片的Python爬虫|Python3中级玩家:淘宝天猫商品搜索爬虫自动化工具(第二篇)
- 简单python爬虫淘宝图片+界面编程+打包成exe
- 爬虫案例---Python2X版本抓取京东手机页面的图片
- 简单python爬虫淘宝图片+界面编程+打包成exe
- python爬虫学习-淘宝图片爬取
- Python 爬虫实战案例 : 煎蛋网全站图片爬虫
- Python3爬虫抓取TP官网案例图片
- 简单的抓取淘宝图片的Python爬虫
- 图解“淘宝商品图片”网页爬虫制作的相关问题
- python爬虫淘宝图片+GUI+打包成exe
- Python-简单的爬虫案例(百度贴吧-图片)
- 爬虫 scrapy 框架学习 2. Scrapy框架业务逻辑的理解 + 爬虫案例 下载指定网站所有图片
- python爬虫数据-下载图片经典案例