import json
import requests
from bs4 import BeautifulSoupinput_name = input('请输入搜索关键字:')# 获取京东商品前50页的信息,包括名称,价格,图片,商店
def get_jd():#循环获得网页urlfor i in range(1, 51):#定义请求头headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) ''AppleWebKit/537.36 (KHTML, like Gecko) ''Chrome/63.0.3239.132 Safari/537.36','upgrade-insecure-requests': '1',}url = 'https://search.jd.com/Search?keyword={}&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&page={}'.format(input_name, 2*i-1)#获取网页html = requests.get(url, headers=headers).content.decode('utf-8')#分析网页soup = BeautifulSoup(html, 'lxml')li_list = soup.find_all('li', class_='gl-item')detail_list = []for li in li_list:#提取需要内容image = 'https:' + li.find('div', class_='p-img').find('a').find('img')['source-data-lazy-img']price = li.find('div', class_='p-price').find('i').textname = li.find('div', class_='p-name').find('i').textshop = li.find('div', class_='p-shopnum').text#生成字典dict1 = {'name': name,'image': image,'price': price,'shop': shop}detail_list.append(dict1)return detail_list
#保存内容
def save_content(contents):#定义文件标题filename = input_name + '.txt'for content in contents:with open(filename, 'a', encoding='utf-8') as f:#将字典转化为json对象保存在文件中f.write(json.dumps(content, ensure_ascii=False))
#执行函数
def main():content = get_jd()save_content(content)if __name__ == '__main__':main()

python爬虫 爬取京东网页相关推荐

  1. chrome动态ip python_用Python爬虫爬取动态网页,附带完整代码,有错误欢迎指出!...

    系统环境: 操作系统:Windows8.1专业版 64bit Python:anaconda.Python2.7 Python modules:requests.random.json Backgro ...

  2. Python爬虫爬取动态网页

    系统环境: 操作系统:Windows8.1专业版 64bit Python:anaconda.Python2.7 Python modules:requests.random.json Backgro ...

  3. python爬虫爬取京东、淘宝、苏宁上华为P20购买评论

    爬虫爬取京东.淘宝.苏宁上华为P20购买评论 1.使用软件 Anaconda3 2.代码截图 三个网站代码大同小异,因此只展示一个 3.结果(部分) 京东 淘宝 苏宁 4.分析 这三个网站上的评论数据 ...

  4. 利用python爬虫爬取京东商城商品图片

    笔者曾经用python第三方库requests来爬取京东商城的商品页内容,经过解析之后发现只爬到了商品页一半的图片.(这篇文章我们以爬取智能手机图片为例) 当鼠标没有向下滑时,此时查看源代码的话,就会 ...

  5. 使用Python爬虫爬取简单网页(Python爬虫入门)

    今天我们来看一看使用Python爬取一些简单的网页. 所用工具:IDLE (Python 3.6 64-bit) 一. 爬取京东商品页面 我将要爬取的是这个东京商品页面信息,代码如下: import ...

  6. python爬虫爬取京东商品评价_网络爬虫-爬取京东商品评价数据

    前段时间做商品评价的语义分析,需要大量的电商数据,于是乎就自己动手爬取京东的数据.第一次接触爬虫是使用selenium爬取CNKI的摘要,基于惯性思维的我仍然想用selenium+Firefox的方法 ...

  7. Python爬虫爬取静态网页基本方法介绍

    爬取静态网页的技术 数据请求模块 一.Requests库 发送GET请求 发送POST请求 get请求和post请求两者之间的区别 处理响应 定制请求头 验证Cookie 保持会话 二.urllib库 ...

  8. Python爬虫爬取静态网页实例一:爬取内涵段子吧上的段子

    最近在学爬虫,这里用实例来与大家分享一下我学习的经验. 这里讲一个爬取静态网页内容的实例,Python一般利用正则表达式爬取静态静态网页的内容,而且因为静态网页源代码固定,不会发生变化,所以比较简单, ...

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

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

最新文章

  1. hive sqoop 分区导入_Sqoop概述及shell操作
  2. 子module 引入so库,aar文件配置
  3. python网课一般多少钱-学习python的时候观看网课学习还是买书学习效率高?
  4. Ubuntu18.04 VMtools的安装与卸载
  5. linux下的mysql修改默认编码
  6. Windows7系统下安装redis的操作教程
  7. Android SubsamplingScaleImageView(subsampling-scale-image-view)单双击长按事件【系列2】
  8. php 嵌套函数公式解析,Pyparsing,使用嵌套解析器解析php函数注释块的内容
  9. 英特尔移动CPU参数表
  10. 桌面支持--dcc打印机设置注意
  11. Java后台调用高德地图api返回{status:0,info:UNKNOWN_ERROR,infocode:20003}
  12. 渣打称中国房市出现泡沫
  13. Flutter实战-请求封装(五)之Isolate线程改造
  14. css3(属性选择器,结构伪类选择器,伪元素选择器 ,css3盒子模型,滤镜filter, cale, 过渡transition))
  15. 【思维导图】本博客技术思维导图
  16. android常用api大全,Android相关常用API……
  17. ajax接口写法,ajax 请求常用写法
  18. 10以内加减法编程_500字以内的面向对象编程。
  19. 迷宫问题 深度优先搜索【c++】
  20. Vuforia官方文档-01-Vuforia功能概述

热门文章

  1. android 截屏 简书,Android 内置应用截屏方法
  2. 深度解析小米净水器不能接管线机的问题
  3. 解决echart在tab中切换时显示不正确
  4. win 下 docker 环境配置
  5. ffmpeg 安装bzlib_centos6中yum安装ffmpeg
  6. python数据挖掘 | 期末题
  7. iOS 开发者开证书创建流程
  8. Tensorflow小白实战系列
  9. html网页中圆角边框的编写,Html实现边框圆角的实例详解
  10. rfc3550-rtp:一种实时应用的传输协议