python爬取京东商品信息(GUI版本)
off999 2024-09-26 16:16 48 浏览 0 评论
前言
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。
作者:DYblog
PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取
下面直接上代码,看不懂的可以看这篇文章或者注释来学习
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
#from openpyxl import *#写入表格使用,写入txt时报错
import time
from tkinter import *
import tkinter.messagebox
from tkinter import ttk
########import结束############
#----------全局变量-----------
https = 'https:'
headers = {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.16 Safari/537.36",
}#定义头部信息,防止被网站阻止
name = []
price = []
introduct = []
urlss = []
#----------全局变量结束-------
#===============函数区域==============
#--------图形界面函数开始--------
def genxin():
top = Tk()
top.title("'%s'在'京东'中查询结果"%E1.get())
top.geometry("800x600+600+100")
columns = ("物品名", "价格", "简介", "链接")
treeview = ttk.Treeview(top, show="headings", columns=columns, height='100')
treeview.column("物品名", width=200, anchor='center')
treeview.column("价格", width=50, anchor='center')
treeview.column("简介", width=200, anchor='center')
treeview.column("链接", width=50, anchor='center')
treeview.heading("物品名", text="物品名")
treeview.heading("价格", text="价格")
treeview.heading("简介", text="简介")
treeview.heading("链接", text="链接")
treeview.pack()
print(name)
print(price)
print(introduct)
print(urlss)
for write_ in range(min(len(name),len(price),len(introduct),len(urlss))): # 写入数据
treeview.insert('', write_, values=(name[write_], price[write_], introduct[write_], urlss[write_]))
top.mainloop()
#--------图形界面函数结束--------
def searchstart():#打开页面查找,获取html
url='https://search.jd.com/Search?keyword='+E1.get()
url = str(url)
html = requests.get(url,headers=headers).text#打开链接,获取html
soup = BeautifulSoup(html, 'html.parser')
for div in soup.find_all('div',class_="ml-wrap"):#包含价格,销量,商品,页数
for shangpin in div.find_all('div',class_="goods-list-v2 gl-type-1 J-goods-list"):
for prices in shangpin.find_all('div',class_="p-price"):#商品价格
for pricess in prices.find_all('i'):
if pricess=='':
pricess='无'
price.append(pricess.text)
for shangpin in div.find_all('div',class_="goods-list-v2 gl-type-1 J-goods-list"):#商品
for name_ in shangpin.find_all('div',class_="p-name p-name-type-2"):
for titlename in name_.find_all('em'):#简介
if titlename=='':
titlename='无'
introduct.append(titlename.text)
for name_ in shangpin.find_all('div',class_="p-name p-name-type-2"):
for introduction in name_.find_all('a',target="_blank"):#商品名
introduction = introduction.get('title')
if introduction=='':
introduction='无'
name.append(introduction)
for url in shangpin.find_all('div',class_="p-name p-name-type-2"):
for urls in url.find_all('a'):
urlss.append(https+urls['href'])
print(introduct)
print(name)
genxin()
#===============函数区域结束==========
##########图形界面开始#########
root = Tk()
root.title('京东商品 查询')
root.geometry('250x160')
L1 = Label(root, text="商品名: ")
L1.place(x = 5,y = 15)
E1 = Entry(root, bd =2)
E1.place(x = 60,y = 15)
A = Button(root, text ="确定",font=('Arial', 12), width=10, height=1,command=searchstart)
A.place(x = 350,y = 10)#确定按钮
root.mainloop()
运行截图:
相关推荐
- bios能看到硬盘 开机找不到硬盘
-
bios里可以看到硬盘,说明硬盘已经被主板识别。进系统找不到,可能硬盘没分区,或者硬盘是动态磁盘,还没有导入或激活。按win+r,输入diskmgmt.msc回车,就打开磁盘管理了,在里面可以给新硬盘...
- 无线网有个红叉(无线网有个红叉,搜索不到网络)
-
连接失败,路由坏换路由,外网坏,报修无线网络处出现红叉表示设备无法正常工作。请检查网卡驱动是否正常,无线网络开关是否打开。解决方法:查看电脑是否有无线网络开关,且是否打开。进入设备管理器检查网卡驱动是...
- thinkpad笔记本官网首页(thinkpad官方商城)
-
官方网站 国内:http://www.thinkworld.com.cn 国内用户只需要访问国内即可。 ThinkPad,中文名为“思考本”,在2005年以前是IBMPC事业部旗下的便携式计算机...
- win7什么版本最好用(win7哪个版本最稳定流畅)
-
Windows7旗舰版,最好,最稳定。Windows7,是由微软公司(Microsoft)开发的操作系统,内核版本号为WindowsNT6.1。Windows7可供选择的版本有:简易版(Sta...
- win7自带虚拟光驱怎么使用(win7系统虚拟光驱安装教程)
-
以DAEMONTools为例,360软件管家里面就有最新版的下.安装后使用方法如下:第一种方法:在虚拟光驱界面中,你先按一下中间工具栏最左边“+”符号的按钮,添加镜像文件(可以一次添加多个),这...
- 电脑装系统蓝屏(电脑装系统蓝屏重启开不了机)
-
蓝屏的原因往往集中在不兼容的硬件和驱动程序、有问题的软件、病毒等。解决办法:1、病毒的原因。使用电脑管家杀毒。2、内存的原因。用橡皮擦把内存条的金手指擦拭一下,把氧化层擦掉,确保内存条安装、运行正常。...
- u盘安装软件(u盘安装软件到电视)
-
第一种情况:软件安装包可以直接下载的。在电脑上将软件安装包下载到本地硬盘,然后将下载好软件安装包拷贝到U盘上即可拿到别的电脑上去安装。分可为exe格式的和rar格式,exe格式直接安装,rar格式的解...
- microsoft官网账户注册(microsoft 帐户注册)
-
要创建Microsoft账户,您可以按照以下步骤进行操作:1.打开任意一个支持浏览器的设备,如电脑、手机或平板电脑。2.在浏览器中输入"Microsoft账户注册"或直接访问Mic...
- 显示器闪屏是什么原因(显示器闪屏是哪里坏了)
-
解决方法: 一、接触不良导致的显示器闪屏 先查看主机和显示器的电源线连接,是否松动,重新插拔一下电源线。 二、信号干扰导致的显示器闪屏 1、连接显示器的电缆线是否没有屏蔽线圈,如果没有防干扰的...
- 国产linux操作系统(国产linux操作系统有什么版本)
-
中国对于操作系统的探索其实并不晚。 早在20世纪60年代中期中国就开始操作系统的研发,那时的比尔·盖茨还只是个迷恋计算机的小字辈,南京大学教授孙钟秀、北京大学杨芙清院士等都是我国操作系统的拓荒者...
- 免费无需排队的云电脑(不需要排队的云电脑)
-
目前市场上有一些云游戏平台提供无限时长且无需排队的服务。这些平台通常采用先进的云计算技术和高性能服务器,能够提供稳定流畅的游戏体验。用户可以随时登录并畅玩游戏,无需等待排队。这些平台还提供多种游戏选择...
- wps官方下载(wps官方下载官网电脑版网址)
-
具体的步骤如下:1、首先在电脑上打开浏览器,在浏览器中输入“WPS”,找到WPS官方网站。2、接下来进入WPS官方网站中,找到WPS软件,点击“免费下载”。3、点击下载后在弹出来的对话框中修改下载位置...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
python入门到脱坑 输入与输出—str()函数
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
慕ke 前端工程师2024「完整」
-
失业程序员复习python笔记——条件与循环
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
