【Python】抓取京东列表页商品信息(selenium)
来源:互联网 发布:imp oracle 导入数据 编辑:程序博客网 时间:2024/05/12 23:35
分析
- url:https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=%E6%89%8B%E6%9C%BA&cid2=653&cid3=655&page=1&s=1&click=0
- 每页的商品共有60个,页面先加载前30个,下滑滚动时再加载后30个
- 故用selenium模拟浏览器下滑操作,再将页面源码给bs4进行解析抽取
代码
# -*- coding: utf-8 -*-import timefrom selenium import webdriverfrom bs4 import BeautifulSoupurl = "https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=%E6%89%8B%E6%9C%BA&cid2=653&cid3=655&page=1&s=1&click=0"driver = webdriver.Firefox()driver.implicitly_wait(3)driver.get(url)# 模拟下滑到底部操作for i in range(1, 5): driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") time.sleep(1)# 将加载好的页面源码给bs4解析soup = BeautifulSoup(driver.page_source, "html.parser")# 进行信息的抽取(商品名称,价格)goods_info = soup.select(".gl-item")for info in goods_info: title = info.select(".p-name.p-name-type-2 a")[0].text.strip() price = info.select(".p-price")[0].text.strip() print title print pricedriver.close()
效果
阅读全文
1 0
- 【Python】抓取京东列表页商品信息(selenium)
- Python+Selenium+Chrome抓取京东商品信息
- CasperJS 抓取京东商品详情页中的商品信息
- 爬虫实践---Selenium-抓取淘宝搜索商品信息
- python +selenium 爬取淘宝网商品信息
- 使用python + selenium爬取淘宝商品信息
- Python抓取华中大二手市场商品信息
- <四>、python爬虫抓取购物网站商品信息--图片价格名称
- 京东商品信息爬虫
- 基于selenium和requests的京东商品信息和评论爬虫
- python+selenium搜狗微信主页抓取
- selenium + python 下拉列表
- 【Python】抓取淘宝列表页信息
- [Python] (多线程版本)抓取聚划算页面商品分析页面获取商品信息并以XML格式保存到本地
- python爬虫(抓取百度新闻列表)
- 【Python】模拟登陆并抓取拉勾网信息(selenium+phantomjs)
- 如何抓取淘宝上的商品信息和详情页信息
- python selenium 下拉列表定位
- 框架整合____SSH框架整合(主流整合方式,最易懂整合方式)
- POJ
- HDU 母函数简单题
- eclipse中配置activiti-5.18.0
- GCD
- 【Python】抓取京东列表页商品信息(selenium)
- PL2887|PL2887牛叉代理商|规格书|应用说明书|现货|价格|方案设计
- Spring mode = "aspectj" 配置事务报错
- 子组件向父组件传值
- 数据结构头结点链表
- JQuery实现购物车数量加减总价累加
- Spring事务
- mysql中 show index from tb_name命令各列的含义,mysql binary 含义
- django 部署后一直返回500