使用requests和re库对淘宝商品信息进行定向爬取
来源:互联网 发布:黄金烤鸡腿堡 知乎 编辑:程序博客网 时间:2024/06/06 08:47
#coding=utf-8import requestsimport redef 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(list, 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]) list.append([price, title]) except: print("")def getGoodsList(list): tplt = "{:4}\t{:8}\t{:16}" print(tplt.format("序号", "价格", "商品名称")) count = 0 for g in list: 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 getGoodsList(infoList)if __name__ == '__main__': main()
阅读全文
0 0
- 使用requests和re库对淘宝商品信息进行定向爬取
- requests模块实践:爬取淘宝商品信息和价格
- 使用python + selenium爬取淘宝商品信息
- requests-re-bs4 定向爬取股票信息
- selenium和pyquery爬取淘宝美食商品信息
- python +selenium 爬取淘宝网商品信息
- 使用python利器selenium工具模拟浏览器运行并爬取淘宝商品信息
- Python 淘宝商品价格爬取(requests库+正则表达式)
- 比价网站的基础-爬取淘宝的商品信息
- 淘宝搜索定向爬取
- 利用requests和正则表达式re爬取猫眼电影top100,并下载图片
- Scrapy爬取亚马逊商品信息
- python3使用requests爬取糗事百科入mongodb库
- 使用requests爬取豆瓣《长城》影评
- 使用requests爬取豆瓣电影top250
- python爬虫学习 之 定向爬取 淘宝商品价格
- requests爬取小说
- 【开源】scrapy爬取亚马逊商品信息
- C语言学习基本字符集
- 线性代数-【2-(3-4)】矩阵及其运算
- C++相关
- 运行时栈帧结构
- <c:set>标签的简单使用
- 使用requests和re库对淘宝商品信息进行定向爬取
- 【mySql数据库初识】
- POJ 1543 Perfect Cubes 笔记
- Unhealthy Nodes导致计算能力下降
- 61. Rotate List
- U盘安装CentOS7是报错:/dev/root not exist
- 状态图(Statechart Diagram)
- 【机房重构】导出到Excel
- c++使用二重指针实现矩阵的储存释放和乘法