python爬虫淘宝比价
来源:互联网 发布:lms算法原理及推导 编辑:程序博客网 时间:2024/05/08 09:53
首先是源码
import reimport requestsdef getHTMLText(url): try: r=requests.get(url,timeout=30) r.raise_for_status() r.encoding=r.apparent_encoding return r.text except: return ""def parsePage(ilt,html): try: plt=re.findall(r'\"view_price\"\:\"[\d\.]*\"',html) tlt=re.findall(r'\"raw_title\"\:\".*?\"',html) for i in range(len(plt)): price=eval(plt[i].split(':')[1]) title=eval(tlt[i].split(':')[1]) ilt.append([price,title]) except: print("")def printGoodsList(ilt):tplt="{:4}\t{:8}\t{:50}"print(tplt.format("序号","价格","商品名称"))count=0for g in ilt:count =count+1print(tplt.format(count,g[0],g[1]))def main():goods='枕头'depth=2start_url="https://s.taobao.com/search?q="+goodsinfoList=[]for i in range(depth):try:url=start_url+'&s='+str(44*i)html=getHTMLText(url)parsePage(infoList,html)except:continueprintGoodsList(infoList)main()
今天在安装requests库时还遇到了一个小问题,就是pip在之前安装可以运行,但是今天却运行不了,通过查找资料和多番尝试,最终我发现,是因为在之前因为 同时安装了python2.7和python3.6,我修改了python的EXE文件的名字。于是我把Python的EXE文件名改回去,再次尝试发现可以运行。
阅读全文
0 0
- python爬虫淘宝比价
- Python网络爬虫与信息提取-Day13-(实例)淘宝商品比价定向爬虫
- python爬虫由浅入深8---基于正则表达式查询的淘宝比价定向爬虫
- python爬虫--淘宝MM
- 淘宝评论爬虫python
- 【python 淘宝爬虫】淘宝信誉分抓取
- 【python 淘宝爬虫】python 淘宝店铺名称,旺旺,销售量 抓取
- 【python 爬虫】python淘宝爬虫实战(selenum+phontomjs)
- 利用Python爬虫,抓取淘宝MM照片
- Python爬虫实战 抓取淘宝照片
- python 爬虫抓取淘宝MM照片
- 淘宝MM资料Python爬虫1.0
- 淘宝MM资料Python爬虫1.2
- 淘宝MM资料Python爬虫1.3
- 淘宝MM资料Python爬虫1.4
- 淘宝MM资料Python爬虫1.5
- Python网络爬虫获取淘宝商品价格
- python爬虫爬取淘宝网页
- JQuery中attr()和prop()用法和区别
- nginx安装第三方ngx_cache_purge模块,purge命令清除静态缓存
- setUserVisibleHint-- fragment真正的onResume和onPause方法
- 初学freertos第二课
- python pip 国内源
- python爬虫淘宝比价
- 关于ajax局部刷新,从数据库实时更新数据到页面(一般是下订单成功后发送消息到后台)
- 数据结构中的时间复杂度的计算
- 基于Extjs在前端页面显示图像,图像上传类型判断
- Codeforces 854 D. Jury Meeting(技巧)
- #数据库#MySQL
- JavaScript之XML
- 目录监控
- C++空间复杂度计算方法