求教:python爬取淘宝页面的图片,网页已经爬取成功,但无法匹配到图片,不知道什么问题,是正则表达式的问题吗?
import urllib.request
import re
'''get access to taobao'''
words="连衣裙"
keywords=urllib.request.quote(words)
#fake header
headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
'''climb the webs and corresponding pictures'''
for i in range(1,3):
url = 'http://s.taobao.com/list?&q='+keywords+'&cat=16&style=grid&seller_type=taobao&bcoffset=0&s='+str(i*60)
data=urllib.request.urlopen(url).read().decode('utf-8', 'ignore')
#此处以上均成功
pat='"pic_url":"//(.*?).jpg"'
pics=re.compile(pat).findall(data)
for j in range (0, len(pics)):
thispic=pics[j]
thispicurl="https://"+thispic
file='E:/python/练习文件/results/taobao_pictures/'+str(i)+str(j)+'.html'
urllib.request.urlretrieve( thispicurl, filename=file )
import re
'''get access to taobao'''
words="连衣裙"
keywords=urllib.request.quote(words)
#fake header
headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
'''climb the webs and corresponding pictures'''
for i in range(1,3):
url = 'http://s.taobao.com/list?&q='+keywords+'&cat=16&style=grid&seller_type=taobao&bcoffset=0&s='+str(i*60)
data=urllib.request.urlopen(url).read().decode('utf-8', 'ignore')
#此处以上均成功
pat='"pic_url":"//(.*?).jpg"'
pics=re.compile(pat).findall(data)
for j in range (0, len(pics)):
thispic=pics[j]
thispicurl="https://"+thispic
file='E:/python/练习文件/results/taobao_pictures/'+str(i)+str(j)+'.html'
urllib.request.urlretrieve( thispicurl, filename=file )
...全文
相关推荐
python爬取并分析淘宝商品信息
python爬取并分析淘宝商品信息背景介绍一、模拟登陆二、爬取商品信息1. 定义相关参数2. 分析并定义正则3. 数据爬取三、简单数据分析1.导入库2.中文显示3.读取数据4.分析价格分布5.分析销售地分布6.词云分析写在最后 Tip:本文仅供学习与交流,切勿用于非法用途!!! 背景介绍 有个同学问我:“XXX,有没有办法搜集一下淘宝的商品信息啊,我想要做个统计”。于是乎,闲来无事的我,又开始琢磨起这事… 一、模拟登陆 兴致勃勃的我,冲进淘宝就准备一顿乱搜: 在搜索栏里填好关键词:“显卡”,小手轻快敲击着回车键(小样~看我的) 心情愉悦的我等待着返回满满的商品信息,结果苦苦的等待换了的却是
Python爬虫爬取一个网页上的图片地址实例代码
主要介绍了Python爬虫爬取一个网页上的图片地址实例代码,具有一定借鉴价值,需要的朋友可以参考下
使用python对淘宝商品信息数据进行爬取
使用python对淘宝数据进行爬取,浏览器需要设置为搜狐浏览器,若不是搜狐浏览器,则需要对浏览器对象进行更改。
python爬取淘宝商品销量信息
主要为大家详细介绍了python爬取淘宝商品的销量信息,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Python爬虫案例1:爬取淘宝网页数据
淘宝网页爬虫代码以及爬取的芒果、草莓、鸭舌帽数据excel文件


