python爬虫爬取APP并封装成API接口调用,使用flask-restful

本文介绍了如何使用Python3.6进行APP爬虫,抓取无忧借条应用的用户信息,并将爬虫集成到Flask-Restful框架中,创建API接口供调用。通过示例代码展示完整流程,并用Postman测试工具验证接口效果。
摘要由CSDN通过智能技术生成

#环境python3.6

# 爬取APP 无忧借条

# 通过用户账号密码爬取用户个人信息(我这账号密码已打码)

爬虫部分代码

# coding:utf8
import hashlib
import time
import urllib3
import json


headers = {'Accept': ' */*', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8',
           'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Redmi 3S Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043632 Safari/537.36 jinjiedao'}
origin_data = {} # 原始数据
result={} #提取后数据
http = urllib3.PoolManager()  # http连接池
urllib3.disable_warnings() #禁用各种urllib3警告

# 获取token
def login(phone,password):
    login_url='https://www.gushistory.com/jjdApi/user/login'
    headers['refer'] = 'https://www.gushistory.com/jjdapp/html/register/login.html?telephone=' + phone
    md5 = hashlib.md5()
    md52 = hashlib.md5()
    md5.update(password.encode(encoding='utf-8')) # 第一次md5
    md52.update(md5.hexdigest().encode(encoding='utf-8'))  # 第二次md5
    # 创建登陆参数字典
    data={'c_telephone': phone, 'c_pwd': md52.hexdigest()}
    response=excute(login_url,'GET',data)
    origin_data['login'] = response
    return response['token']

# 获取登陆后的信息
def getAccountInfo(token):
    account_url='https://www.gushistory.com/jjdApi/user/getHomepageInfo'
    headers['refer'] = 'https://www.gushistory.com/jjdapp/html/index.html'
    data = {'token': token}
    response = excute(account_url, 'GET', data)
    origin_data['account'] = response
    user_info = response['userInfo']
    result['balance'] = user_i
  • 5
    点赞
  • 88
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值