python爬虫二
来源:互联网 发布:java成员变量 默认权限 编辑:程序博客网 时间:2024/06/05 19:55
from bs4 import BeautifulSoupimport requestsdef getHTMLText(): 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_prie\"\:\"[\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 printGoodList(ilt): tplt="{:4}\t{:8}\t{:16}" print(tplt.format("序号","价格","商品名称")) count=0 for g in ilt: count=count+1 print(tplt.format(count,g[0],g[1]))def main(): goods='书包' depth=2 start_url='https://s.taobao.com/search?q'+goods infoList=[] for i in range(depth): try: url=start_url+'&s='+str(44*i) html=getHTMLText(url) parsePage(infoList,html) except: continue printGoodList(infoList)main()
阅读全文
0 0
- python 爬虫(二)
- Python爬虫实例二
- Python爬虫入门二
- python爬虫练手二
- python爬虫(二)
- python爬虫(二)
- Python爬虫入门 (二)
- python爬虫(二)
- python爬虫二
- Python 爬虫(二)
- python爬虫系列二
- Python爬虫知识点二
- Python爬虫(二)图片下载爬虫
- Python爬虫整理(二)
- python爬虫(二)--了解deque
- python简单爬虫(二)
- Python爬虫(二):整体设计
- Python爬虫urllib2笔记(二)
- 洛谷1850【noip2016】换教室
- Redhat7.2网络配置
- 《Android群英传》笔记6——自定义ViewGroup
- POJ3211 Washing Clothes
- caffe中的loss和accuracy曲线
- python爬虫二
- 微博爬虫
- debug\values\generated.xml: Error: Duplicate resources重复定义
- oracle11g查看自动收集统计信息是否开启
- AC自动机萌新讲解
- LIS 两种算法分析+hdu 1950
- 在 Linux 下搭建 Git 服务器
- 智能指针入门
- 传染病问题