分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

用pyspider爬取并解析json字符串

发布时间:2023-09-06 01:13责任编辑:郭大石关键词:jsjson

获取堆糖网站所有用户的id 昵称及主页地址

#!/usr/bin/env python# -*- encoding: utf-8 -*-# Created on 2016-06-21 13:57:13# Project: duitangfrom pyspider.libs.base_handler import *class Handler(BaseHandler): ???crawl_config = { ???} ???@every(minutes=24 * 60) ???def on_start(self): ???????self.crawl(‘http://www.duitang.com/napi/friendship/fans/?start=0&limit=1000&user_id=116965‘, callback=self.index_page) ???@config(age=10 * 24 * 60 * 60) ???def index_page(self, response): ???????for each in ?response.json[‘data‘][‘object_list‘]: ???????????id = each[‘id‘] ???????????self.crawl(‘http://www.duitang.com/napi/friendship/fans/?start=0&limit=1000&user_id=‘+str(id), callback=self.index_page) ???????????self.crawl(‘http://www.duitang.com/napi/people/profile/?user_id=‘+str(id), callback=self.detail_page) ???????start = response.json[‘data‘][‘next_start‘] ????????total = response.json[‘data‘][‘total‘] ???????user = response.json[‘data‘][‘visit_user‘][‘user_id‘] ???????if start < total: ???????????self.crawl(‘http://www.duitang.com/napi/friendship/fans/?start=‘+str(start)+‘&limit=1000&user_id=‘+str(user),callback=self.index_page) ???????@config(priority=2) ???def detail_page(self, response): ???????return { ???????????"username": response.json[‘data‘][‘username‘], ????????????"id": response.json[‘data‘][‘id‘] ???????}

用pyspider爬取并解析json字符串

原文地址:http://www.cnblogs.com/weijunjie/p/7574251.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved