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 一.前言 打过王者的童鞋一般都会喜欢里边设计出来的英雄吧,特别想把王者荣耀的英雄的高清图片当成电脑桌面 ...
随机推荐
- 面试三轮我倒在了一道sql题上——sql性能优化
一.前言 最近小农在找工作,因为今年疫情的特殊原因,导致工作不是特别好找,所以一旦有面试电话,如果可以,都会去试一试,刚好接到一个面试邀请,感觉公司还不错,于是就确定了面试时间,准备了一下就去面试了. ...
- 视频处理之OSD
欲观原文,请君移步 OSD简介 OSD,on-screen display的简称,即屏幕菜单式调节方式.一般我们按一下Menu键后屏幕弹出的显示器各项调节项目信息的矩形菜单,比如调亮度,色调,饱和度等 ...
- iOS -实现imageView中的button响应点击事件的方法
<pre name="code" class="cpp" style="font-size: 13px;">/** imagev ...
- Kubernetes内部域名解析的那些事儿
前言 在kubernets环境中,服务发现大都是基于内部域名的方式.那么就涉及到内部域名的解析.从1.11版本开始,kubeadm已经使用第三方的CoreDNS替换官方的kubedns作为集群内部域名 ...
- 智能家居巨头 Aqara 基于 KubeSphere 打造物联网微服务平台
背景 从传统运维到容器化的 Docker Swarm 编排,从 Docker Swarm 转向 Kubernetes,然后在 Kubernetes 运行 SpringCloud 微服务全家桶,到最终拥 ...
- Copy-on-write + Proxy = ?
一.简介 Immer (German for: always) is a tiny package that allows you to work with immutable state in a ...
- @atcoder - AGC026F@ Manju Game
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个含 N 个数的序列,Alice 与 Bob 在博弈.Al ...
- Linux中GitLab的部署
1.版本控制介绍 版本控制最主要的功能就是追踪文件的变更.它将什么时候.什么人更改了文件的什么内容等信息忠实地了记录下来.每一次文件的改变,文件的版本号都将增加.除了记录版本变更外,版本控制的另一 ...
- 一个非侵入的Go事务管理库——工作原理
在上一篇文章"一个非侵入的Go事务管理库--如何使用"中,我讲述了如何使用事务库.有些读者可能读过"清晰架构(Clean Architecture)的Go微服务: 事物管 ...
- elasticSearch插件metricbeat收集nginx的度量指标
ngx_http_stub_status_module模块是Nginx中用来统计Nginx服务所接收和处理的请求数量,只要在编译安装Nginx的时候加上参数--with-http_stub_statu ...