前言

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。

作者:DYblog

转载:https://www.cnblogs.com/dy8888/p/13257918.html

PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取

python免费资料已上传到学习交流群,可自行下载获取

python学习交流群,点击即可加入

下面直接上代码,看不懂的可以看这篇文章或者注释来学习

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#written by DY
#http://dyblog.tk
#e-mail:duyun888888@qq.com
########import###############
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():#打开页面查找,获取htmlurl='https://search.jd.com/Search?keyword='+E1.get()url = str(url)html = requests.get(url,headers=headers).text#打开链接,获取htmlsoup = 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()
###########图形界面结束#########
#written by DY
#http://dyblog.tk
#e-mail:duyun888888@qq.com

运行截图:

python treeview底部加个按钮_Python爬取京东商品信息(GUI版本)相关推荐

  1. python爬虫爬取京东商品评价_python爬取京东商品信息及评论

    ''' 爬取京东商品信息: 功能: 通过chromeDrive进行模拟访问需要爬取的京东商品详情页(https://item.jd.com/100003196609.html)并且程序支持多个页面爬取 ...

  2. python爬取京东数据加载失败_Python爬取京东商品数据

    对京东某一商品信息页面的HTML代码进行分析,可以发现它的图书产品信息页面都含有这样一段代码(不同类的商品页面有些不同): window.pageConfig={compatible:true,sea ...

  3. go爬虫和python爬虫哪个好_python 爬虫实战项目--爬取京东商品信息(价格、优惠、排名、好评率等)-Go语言中文社区...

    利用splash爬取京东商品信息 一.环境 window7 python3.5 pycharm scrapy scrapy-splash MySQL 二.简介 为了体验scrapy-splash 的动 ...

  4. python爬虫爬商品库存_python爬虫实践——爬取京东商品信息

    1 ''' 2 爬取京东商品信息:3 请求url:4 https://www.jd.com/5 提取商品信息:6 1.商品详情页7 2.商品名称8 3.商品价格9 4.评价人数10 5.商品商家11 ...

  5. layui获取input信息_python爬虫—用selenium爬取京东商品信息

    python爬虫--用selenium爬取京东商品信息 1.先附上效果图(我偷懒只爬了4页) 2.京东的网址https://www.jd.com/ 3.我这里是不加载图片,加快爬取速度,也可以用Hea ...

  6. python爬取京东商品信息代码_爬取京东商品信息

    利用 BeautifulSoup + Requests 爬取京东商品信息并保存在Excel中 一.查看网页信息 打开京东商城,随便输入个商品,就选固态硬盘吧 先看看 URL 的规律,可以看到我们输入的 ...

  7. Selenium介绍--实例爬取京东商品信息与图片

    目录 一.Selenium简介 二.Selenium组成 三.Selenium特点 四.Selenium的基本使用 1.下载所用浏览器需要的驱动 2.创建项目并导入依赖 3.入门 3.代码演示 五.实 ...

  8. Day06,selenium的剩余用法、万能登录破解和爬取京东商品信息,及破解极验滑动验证码...

    一.自动登录抽屉新热榜 from selenium import webdriver import timedriver = webdriver.Chrome(r'D:\BaiduNetdiskDow ...

  9. python爬取京东商品属性_python爬虫小项目:爬取京东商品信息

    #爬取京东手机信息 import requests from bs4 import BeautifulSoup from selenium import webdriver import re imp ...

最新文章

  1. 分布式缓存系统Memcached简介与实践
  2. InitializeComponent System.StackOverflowException
  3. odoo API装饰器one、model、multi的区别
  4. Oracle中的date与timestamp
  5. cakephp视图用php文件,CakePHP - 扩展视图( Extending Views)
  6. 计算机的主存储器可以分为哪两类,2017年计算机应用基础模拟试题「答案」(2)...
  7. SAP MTA打包的一些常见错误
  8. 为什么有转换流,作用是什么?
  9. 只不过是R.java文件的特性-----出错信息:R.java was modified manually! Reverting to generated version!...
  10. 领域驱动设计:浅析 VO、DTO、DO、PO 概念、区别、用处
  11. 深度学习(10):自然语言处理(转)
  12. HTML中轮播图里的圆点不充满,老师好,轮播图中的小点不显示
  13. 考前必背的50个知识点——系统集成项目管理工程师考试
  14. 它!5 年代替狂卷的 CNN!
  15. WebService 服务 转
  16. SAP ABAP BAPI_MATERIAL_AVAILABILITY 查询可用库存
  17. Guided Anchoring 论文笔记
  18. 组织行为学笔记(4)——人格与价值观
  19. 5分钟外设学堂:耳机不响别慌,换个插头能救活!
  20. 企业证书更新与说明/羊毛口子:美团实体跑腿拍照撸1~20元

热门文章

  1. 智能家居 (3) ——智能家居工厂模式介绍实现继电器控制灯
  2. python列表相关函数_python中列表(list)相关的函数
  3. Mybatis之SqlSession简析
  4. @PostConstruct注解学习,最详细的分享教程
  5. 扩展类加载器 Extension ClassLoader
  6. 前端:JS实现数组去重常用的六种方法介绍
  7. 收集53个程序员励志名言
  8. Java工程师该如何编写高效代码?
  9. 【收集】前端技能知识图谱
  10. EF调用存储过程实现分页