资源简介
本人进行学校python课程设计的实战成果,实现的整个过程详见博客。此程序利用网络爬虫技术获取平台购物信息从而实现跨平台比价功能以及相关扩展功能,难度适中,适合作为课设进行开发。

代码片段和文件信息
import requests
import re
import time
import os
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from Goods import Goods
class CrawlProgram:
def getHTMLText(selfurl):
try:
kv = {‘user-agent‘: ‘Mozilla/5.0‘}
r = requests.get(url headers=kv timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
print(‘获取HTML失败‘)
return ““
def getItemsFromTmall(selfkeywordnumber):
# 单个页面最多获取60个商品
url = ‘https://list.tmall.com/search_product.htm?q=‘ + keyword
soup = bs(self.getHTMLText(url) ‘html.parser‘)
try:
# get_title
title_ls = []
for item in soup.find_all(‘p‘ class_=‘producttitle‘):
if item.find(‘a‘):
title_ls.append(item.find(‘a‘).get(‘title‘))
else:
title_ls.append(‘无相关信息‘)
# get_href and id
href_ls = []
id_ls = []
reg = re.compile(r‘\d{515}‘)
for item in soup.find_all(‘p‘ class_=‘producttitle‘):
if item.find(‘a‘):
href = ‘https:‘ + item.find(‘a‘).get(‘href‘)
href_ls.append(href)
id = reg.findall(href)
if id:
id_ls.append(‘T‘+id[0])
else:
id_ls.append(‘无相关信息‘)
else:
href_ls.append(‘无相关信息‘)
# get_monthly_sales
sale_ls = []
for item in soup.find_all(‘p‘ class_=‘productStatus‘):
if item.find(‘em‘):
sale_ls.append(item.find(‘em‘).string[:-1])
else:
sale_ls.append(‘无相关信息‘)
# get_shop_info
shop_ls = []
for item in soup.find_all(‘p‘ class_=‘productStatus‘):
if item.find(‘span‘ class_=True):
shop_ls.append(item.find(‘span‘ class_=True).get(‘data-tnick‘))
else:
shop_ls.append(‘无相关信息‘)
# get_price
price_ls = []
for item in soup.find_all(‘p‘ class_=‘productPrice‘):
if item.find(‘em‘):
price_ls.append(item.find(‘em‘).get(‘title‘))
else:
price_ls.append(‘无相关信息‘)
items = []
for num in range(len(title_ls)):
goods= Goods(id_ls[num]‘天猫‘title_ls[num]shop_ls[num]eval(price_ls[num])sale_ls[num]href_ls[num])
items.append(goods)
return items[:number]
except:
print(‘获取天猫商品信息失败‘)
return []
def getItemsFromJD(selfkeywordnumber):
# 单个页面最多获取30个商品,销量为月销量
url = ‘https://search.jd.com/Search?keyword=‘
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9651 2020-06-12 12:42 python课设--网购平台比价系统(天猫、京东、拼多多)\CrawlProgram.py
文件 3068 2020-06-12 09:23 python课设--网购平台比价系统(天猫、京东、拼多多)\DBConnection.py
文件 3566280 2019-10-12 08:38 python课设--网购平台比价系统(天猫、京东、拼多多)\geckodriver.exe
文件 2786 2020-06-11 13:31 python课设--网购平台比价系统(天猫、京东、拼多多)\Goods.py
文件 1959 2020-06-10 21:21 python课设--网购平台比价系统(天猫、京东、拼多多)\GoodsList.py
文件 12281 2020-06-11 18:30 python课设--网购平台比价系统(天猫、京东、拼多多)\Gui.py
文件 1394 2020-06-12 09:26 python课设--网购平台比价系统(天猫、京东、拼多多)\操作介绍.txt
相关资源
- 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函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
评论
共有 条评论