环境:win10,安卓9,配置好的mitmdump和相关证书

代码

import json
import pymongo
from mitmproxy import ctx


def response(flow):
    # https://entree.igetget.com/ebook2/v1/ranklist/list?requestType=new_rank&count=20&max_id=0 # 新书排行链接
    url = 'https://entree-ws.igetget.com/ebook2/v1/ranklist/list?requestType=total_rank&count=20&max_id=0'  # 热书排行

    # 对url的过滤,只有mitmdump捕捉到符合的url以后,才会导出数据
    if flow.request.url.startswith(url):
        text = flow.response.text
        data = json.loads(text)
        books = data.get('c').get('data')
        for book in books:
            data = {
                'title': book.get('operating_title'),
                'cover': book.get('cover'),
                'summary': book.get('other_share_summary'),
                'introduce': book.get('book_intro'),
                'price': book.get('price')
            }
            save(data)
            ctx.log.info(str(data))
            ctx.log.info('------------------------------------------------------------------------------------------------------')


def save(data):
    client = pymongo.MongoClient(host='localhost')
    db = client.igetget
    collection = db.book
    if data:
        collection.insert(data)

成果
0
1

Ps:有什么问题欢迎大家评论

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐