资源简介
爬取淘宝手机月销售数据,以excel表格形式存储,以条形图形式展示不同品牌手机在淘宝的月销售量。可以通过更改关键字手机实现对其他商品的爬取。详细介绍https://blog.csdn.net/weixin_42911616/article/details/81506154
代码片段和文件信息
import requests
import pygal
import re
from xlwt import Workbook
import matplotlib.pyplot as plt
import xlrd
import time
from pylab import mpl
mpl.rcParams[‘font.sans-serif‘] = [‘FangSong‘] # 指定默认字体
mpl.rcParams[‘axes.unicode_minus‘] = False # 解决保存图像是负号‘-‘显示为方块的问题
def key_name( number ):
#获取页面的内容并返回
name = ‘手机‘
URL_1 = “https://s.taobao.com/search?ie=utf8&initiative_id=staobaoz_20170905&stats_click=search_radio_all%3A1&js=1&imgfile=&q=“
URL_2 = “&suggest=0_1&_input_charset=utf-8&wq=u&suggest_query=u&source=suggest&p4ppushleft=5%2C48&s=“
URL = ( URL_1 + name + URL_2 + str(number))
#print(URL)
res = requests.get( URL )
return res.text
def find_date( text):
#根据整个页面的信息,获取商品的数据所在的HTML源码并放回
reg = r‘“data“:{“spus“:\[({.+?)\]}}“header“:‘
reg = re.compile(reg)
info = re.findall(reg text)
return info[0]
def manipulation_data( info sales_count sheet ):
#解析获取的HTML源码,获取数据
Date = eval(info)
for d in Date:
T = “ “.join([t[‘tag‘] for t in d[‘tag_info‘]])
#print(d[‘title‘] + ‘\t‘ + d[‘price‘] + ‘\t‘ + d[‘importantKey‘][0:len(d[‘importantKey‘])-1] + ‘\t‘ + T)
#将数据写入对应的excel表格中
sheet.write(sales_count[‘line‘]0d[‘title‘])
sheet.write(sales_count[‘line‘]1int(d[‘price‘]))
sheet.write(sales_count[‘line‘]2int(d[‘month_sales‘]))
sheet.write(sales_count[‘line‘]3T)
#统计不同品牌手机的月销售量
for key in sales_count.keys():
if str(d[‘title‘]).find(‘荣耀‘)>=0:
sales_count[‘华为‘]=sales_count[‘华为‘]+(int(d[‘month_sales‘]))
elif str(d[‘title‘]).find(str(key))>=0:
sales_count[key]=sales_count[key]+(int(d[‘month_sales‘]))
sales_count[‘line‘]= sales_count[‘line‘] + 1
return sales_count
def show(sales_count):
#按照手机销售量进行排序并绘图(网页版)
sales_count=dict
- 上一篇:python+mysql人力资源管理系统
- 下一篇:python爬取京东手机销售数据
相关资源
- Python-BDD100K大规模多样化驾驶视频数据
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 一个多线程智能爬虫,爬取网站小说
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- 顶点小说单本书爬虫.py
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
评论
共有 条评论