# 将响应中百度的 logo“”替换为“谷歌的 logo” text = flow.response.get_text() text = text.replace("//www.baidu.com/img/bd_logo1.png", "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png") flow.response.set_text(text)
效果
爬取得到 APP 电子书存入 MongoDB(来源 python 爬虫)
import json import pymongo from mitmproxy import ctx
client = pymongo.MongoClient('localhost') db = client['igetget'] collection = db['books']
def response(flow): global collection url = 'https://dedao.igetget.com/v3/discover/bookList' if flow.request.url.startswith(url): text = flow.response.text data = json.loads(text) books = data.get('c').get('list') for book in books: data = { 'title': book.get('operating_title'), 'cover': book.get('cover'), 'summary': book.get('other_share_summary'), 'price': book.get('price') } ctx.log.info(str(data)) collection.insert(data)