python爬京东(带GUI)
最近写了个专门爬百度的,后来又想爬京东的,还是采用上次的BeautifulSoup+requests模块
下面直接上代码,看不懂的可以看这篇文章或者注释来学习
#!/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():#打开页面查找,获取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('500x600')
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
如果有不懂的,可以直接留言或者联系duyun888888@qq.com
python爬京东(带GUI)的更多相关文章
- python实现的、带GUI界面电影票房数据可视化程序
代码地址如下:http://www.demodashi.com/demo/14588.html 详细说明: Tushare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采 ...
- Python 实现的、带GUI界面的词云生成器
代码地址如下:http://www.demodashi.com/demo/14233.html 详细说明: "词云"就是数据可视化的一种形式,给出一段文本,根据文本中词语的出现频率 ...
- python自带gui插件tkinter使用小结
1.tkinter简介 Tkinter(即 tk interface,简称"Tk")本质上是对 Tcl/Tk 软件包的 Python 接口封装,它是 Python 官方推荐的 GU ...
- python爬虫系列之爬京东手机数据
python抓京东手机数据 作者:vpoet mail:vpoet_sir@163.com #coding=utf-8 import urllib2 from lxml import etree im ...
- 用Python爬取分析【某东618】畅销商品销量数据,带你看看大家都喜欢买什么!
618购物节,辰哥准备分析一波购物节大家都喜欢买什么?本文以某东为例,Python爬取618活动的畅销商品数据,并进行数据清洗,最后以可视化的方式从不同角度去了解畅销商品中,名列前茅的商品是哪些?销售 ...
- Python爬取南京市往年天气预报,使用pyecharts进行分析
上一次分享了使用matplotlib对爬取的豆瓣书籍排行榜进行分析,但是发现python本身自带的这个绘图分析库还是有一些局限,绘图不够美观等,在网上搜索了一波,发现现在有很多的支持python的绘图 ...
- Python3.x:Selenium+PhantomJS爬取带Ajax、Js的网页
Python3.x:Selenium+PhantomJS爬取带Ajax.Js的网页 前言 现在很多网站的都大量使用JavaScript,或者使用了Ajax技术.这样在网页加载完成后,url虽然不改变但 ...
- 萌新学习Python爬取B站弹幕+R语言分词demo说明
代码地址如下:http://www.demodashi.com/demo/11578.html 一.写在前面 之前在简书首页看到了Python爬虫的介绍,于是就想着爬取B站弹幕并绘制词云,因此有了这样 ...
- python 爬取王者荣耀高清壁纸
代码地址如下:http://www.demodashi.com/demo/13104.html 一.前言 打过王者的童鞋一般都会喜欢里边设计出来的英雄吧,特别想把王者荣耀的英雄的高清图片当成电脑桌面 ...
随机推荐
- KVM Web管理平台 WebVirtMgr
WebVirtMgr介绍 WebVirtMgr是一个KVM管理平台,让kvm管理变得更为可视化,对中小型kvm应用场景带来了更多方便.WebVirtMgr采用几乎纯Python开发,其前端是基于Pyt ...
- https如何进行加密传输
客户端是没有证书的,也就没有公钥和私钥. SSL握手阶段,服务器把证书传输给客户端,同时也就传输了公钥(公钥是证书的一部分). 由客户端来对这个证书进行有效性认可,再由这个客户端来生成对称密钥. 对称 ...
- test tt=0 <=>test(0)
class test{ int mvalue; public: test(int i){ cout << "test(int i) =" << i < ...
- centos6 升级python2.6 到 python2.7
由于开发库依赖于python27,而自己安装的centos6.8自带的python是2.6.6. 因为centos的yum依赖于python26因此不打算覆盖26. 步骤如下: 1.官网下载源码压缩包 ...
- 02.DRF-认识RESTful
认识RESTful 在前后端分离的应用模式里,后端API接口如何定义? 例如对于后端数据库中保存了商品的信息,前端可能需要对商品数据进行增删改查,那相应的每个操作后端都需要提供一个API接口: POS ...
- Android学习笔记使用AlertDialog实现对话框
使用AlertDialog可以实现如下对话框 案例 布局问文件就加了几个Button,我直接上Java代码了 实现显示带取消,确定按钮的对话框按钮 Button showDialogOne = fin ...
- WeChair项目Alpha冲刺(6/10)
团队项目进行情况 1.昨日进展 Alpha冲刺第六天 昨日进展: 前端:和后端成功交互,页面修改和完善 后端:和前端成功交互,但是数据解密失败,初步编写登录的service层和dao层代码未测试 ...
- mysql主从同步参数
默认情况下,mysql的主从同步,会启用三个线程,两个IO线程和一个SQL线程.主从同步的主要文件就是binlog文件,从库从主库的binlog中读取数据,然后记录在从库自己的relaylog中,然后 ...
- 【asp.net core 系列】12 数据加密算法
0. 前言 这一篇我们将介绍一下.net core 的加密和解密.在Web应用程序中,用户的密码会使用MD5值作为密码数据存储起来.而在其他的情况下,也会使用加密和解密的功能. 常见的加密算法分为对称 ...
- Spring Boot Admin 2.1.4最新实战教程
环境的搭建 首先搭建eruka的注册中心 pom.xml <?xml version="1.0" encoding="UTF-8"?> <pr ...