最近写了个专门爬百度的,后来又想爬京东的,还是采用上次的BeautifulSoup+requests模块

很多人学习python,不知道从何学起。
很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手。
很多已经做案例的人,却不知道如何去学习更加高深的知识。
那么针对这三类人,我给大家提供一个好的学习平台,免费领取视频教程,电子书籍,以及课程的源代码!
QQ群:1097524789

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

#!/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爬京东(带GUI)相关推荐

  1. python中求根公式_用python做个带GUI的求根公式吧

    用python做个带GUI的求根公式吧 解题程序 在本文中,将用python实现解一元二次方程ax^2+bx+c=0(a≠0)的求根公式,并设计基于TK的GUI界面. 实现效果 程序编写 整体 GUI ...

  2. python:实现带GUI界面的Youtube下载器(附完整源码)

    python:实现带GUI界面的Youtube下载器 from pytube import * import os from tkinter import * from tkinter.filedia ...

  3. python爬京东联盟_python爬虫框架scrapy实战之爬取京东商城进阶篇

    前言 之前的一篇文章已经讲过怎样获取链接,怎样获得参数了,详情请看python爬取京东商城普通篇,本文将详细介绍利用python爬虫框架scrapy如何爬取京东商城,下面话不多说了,来看看详细的介绍吧 ...

  4. python词云去除词_使用Python制作一个带GUI界面的词云自动生成工具(连载五)

    上一篇中我们介绍了自动生成词云工具(GUI)中数据清洗界面的实现过程(详解词云自动生成工具的数据清洗界面制作过程(连载四)),了解掌握了Grid.Pack混合布局的方法.本篇我们将讨论Python自动 ...

  5. python爬京东延迟加载_python大规模爬取京东

    python大规模爬取京东 主要工具 scrapy BeautifulSoup requests 分析步骤 打开京东首页,输入裤子将会看到页面跳转到了这里,这就是我们要分析的起点 我们可以看到这个页面 ...

  6. python制作软件界面_使用Python制作一个带GUI界面的词云自动生成工具(一)

    在现实生活中你可能会遇到这种情况:想知道一篇论文中哪个词语最多,哪些词语最少(以此判断文章的主要内容):想知道一部小说中哪一个人物出现的次数最多(当然,出现次数最多的那个人也不一定是主脚):想知道一部 ...

  7. python color属性_使用Python制作一个带GUI界面的词云自动生成工具(连载七)

    前几篇向大家介绍了词云自动生成工具(GUI)的详解GUI词云自动生成工具中词云属性设置界面的实现(连载六).通过前面内容我们基本构建出了词云自动生成工具的主要框架.本篇结合tkinter中的filed ...

  8. python爬京东 反爬_京东的验证码和反爬都很烦人吧?那又怎样,照样轻松爬取京东数据...

    目标 爬取京东商城上iphone x用户评论数据: 使用jieba对评论数据进行分词处理: 使用wordcloud绘制词云图. 进群:548377875即可获取数十套pdf哦! 然后我们会发现这个接口 ...

  9. python爬京东优惠券_京东抽奖爬虫LiteVersion

    京东全能工具包 JDPackage V2.3 作者接一切数据&Web&小程序开发外包服务,介绍人提供10%-20%佣金.可签合同.开正规公司发票. 作者2018.8.27留 感谢大 ...

最新文章

  1. UIPopoverController在ARC环境下用法注意
  2. Playmaker全面实践教程之Playmaker常用工具
  3. 3000 字说说跨域!面试官听完之后露出了满意的笑容
  4. Selenium3+MySQL数据库进行数据驱动测试
  5. 后门怎么写隐蔽java_用Java写黑软-后门篇
  6. Chapter4-2_Speech_Synthesis(More than Tacotron)
  7. 关于Hystrix的几个问题
  8. 使用webpack打包ThinkPHP的资源文件
  9. jmeter JDBC Request
  10. C++ 以智能指针管理内存资源
  11. SpringBoot集成 Shiro
  12. springboot controller调用service_秀!这款工具让SpringBoot不再需要Controller、Service、DAO、Mapper!...
  13. 树莓派模拟电路_基于树莓派的热电偶测量模块 MCC 134
  14. 电脑录音软件如何录制YY语音
  15. 晶振负载电容是什么意思?关于晶振负载电容
  16. 设计模式的艺术 结构性模式之组合模式
  17. 小巧时尚的机械键盘,通吃五台设备,雷柏MT510PRO键盘体验
  18. win11系统输入法增加小鹤双排
  19. 一起学习R语言吧——R语言+RStudio
  20. WADISWAT数据处理

热门文章

  1. Python: 装饰器的小例子
  2. WPF MVVC 基础 - 父子窗体
  3. 取模(mod)与取余(rem)的区别——Matlab学习笔记
  4. jQuery-图片上传裁剪插件--imgAreaSelect(分析一) 放大缩小
  5. [转载](热议)“我不伟大”,但可以让善良“春暖花开”
  6. SDKMAN - 一个用于轻松管理多个软件开发工具包的CLI工具
  7. 数据可视化组件Grafana详细解读--Debian/Ubuntu上的安装
  8. CCNA——网络初认识
  9. JDK1.8源码下载及获取、导入IDEA阅读、配置JDK源码
  10. React v16版本 源码解读