资源简介
爬取京东手机销售与评价数据,以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
from selenium import webdriver
from bs4 import BeautifulSoup
mpl.rcParams[‘font.sans-serif‘] = [‘FangSong‘] # 指定默认字体
mpl.rcParams[‘axes.unicode_minus‘] = False # 解决保存图像是负号‘-‘显示为方块的问题
def key_name( drivernumber ):
#获取页面的内容并返回
name = ‘手机‘
URL_1 = “https://search.jd.com/Search?keyword=“
URL_2 = “&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=“
URL_3=“&cid2=653&cid3=655&page=“
URL_4 = “&s=1&click=0“
URL = ( URL_1 + name + URL_2 + name + URL_3+ str(number)+URL_4)
#driver = webdriver.Firefox()
#driver.implicitly_wait(3)
driver.get(URL)
# 模拟下滑到底部操作
for i in range(1 5):
driver.execute_script(“window.scrollTo(0 document.body.scrollHeight);“)
time.sleep(1)
# 将加载好的页面源码给bs4解析
soup = BeautifulSoup(driver.page_source “html.parser“)
t=0
# 进行信息的抽取(商品名称,价格)
goods_info = soup.select(“.gl-item“)
#driver.close()
return goods_info
def manipulation_data( goods_info sales_count sheet ):
#解析获取的HTML源码,获取数据并对数据进行解析
count=0
for info in goods_info:
title = info.select(“.p-name.p-name-type-2 a“)[0].text.strip()
price_str = info.select(“.p-price“)[0].text.strip()
count_str = info.select(“.p-commit“)[0].text.strip()
#print (title)
price_start=price_str.find(‘¥‘)+1
price_end=price_str.find(‘.‘)
price=int(price_str[price_start:price_end])
#print (price)
if(count_str.find(‘\n‘))>=0:
count_start=count_str.find(‘\n‘)+1
else:
count_start=0
if(count_str.find(‘万+‘))>=0:
count=float(count_str[count_start:count_str.find(‘万‘)])*10000
elif(count_str.find(‘+‘))>=0:
count=int(count_str[count_start:count_str.find(‘+‘)])
#print(count)
sheet.write(sales_count[‘line‘]0title)
sheet.write(sales_count[‘line‘]1int(price))
sheet.write(sales_count[‘line‘]2int(count))
for key in sales_count.keys():
if str(title).find(‘荣耀‘)>=0:
相关资源
- 易语言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应用
评论
共有 条评论