资源简介
爬取实时搜索商品,python开发,web技术是简单的Flask,最小的代码爬取你想要的商品信息
代码片段和文件信息
from flask import Flask request session g redirect url_for abort render_template flash jsonify json
import urllib.request
from lxml import etree
import json
from bson import json_util
# url = “https://d.jd.com/area/get?fid=1“
# url = “https://raw.githubusercontent.com/modood/Administrative-divisions-of-China/master/dist/pcas-code.json“
# url = “https://item.m.jd.com/ware/detail.json?wareId=16148156042“
# url = “https://so.m.jd.com/ware/search.action?keyword=iphoneX&searchFrom=home“
# https://item.m.jd.com/product/{}.html?sid=d9d3d16e61e773961d1acc8df469eb43sku_id #手机端H5详情
app = Flask(__name__)
def toJson(data):
return json.dumps(
data
default=json_util.default
ensure_ascii=False
)
def toobject(data):
return json.loads(
data
encoding=“utf-8“
)
@app.route(‘/search‘ methods=[‘GET‘])
@app.route(‘/search/- ‘ methods=[‘GET‘])
def get_goods(item=None):
if request.method == ‘GET‘:
jsons = request.args.get(‘json‘ ‘on‘)
keyword = request.args.get(‘key‘ ‘‘)
if not keyword:
keyword = item
# keyword = “iphoneX“
keyword = urllib.parse.quote(keyword) #url中的中文字符处理
print(keyword)
search_url = ‘https://search.jd.com/Search?keyword={key}&enc=utf-8&page={page}‘
response = urllib.request.urlopen(search_url.format(key=keywordpage=1))
content = response.read().decode(‘utf-8‘)
response.close()
tree = etree.HTML(content)
sku_id = tree.xpath(‘//div[@id=“J_goodsList“]/ul/li/@data-sku‘)
# item_url = []
detail_json = []
i = 0
for one_sku in sku_id:
# 取10条 判断
if i < 10:
# pr
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论