环境:win7
时间:2019-10-1
最近在学习爬取app数据,参考崔庆才大佬的书 《python3网络爬虫开发实战》中的第十一章
在安装好mitmdump后,运行自定义脚本开始抓包却出现了错误。
现在记录下遇到的问题:
安装mitmproxy
pip install mitmproxy
按照网上的教程安装证书,给手机也安装证书
启动mitmproxy(win换环境下,无法直接开启mitmproxy)
mitmdump
mitmweb
要爬取的数据(得到app—电子书—新书top100)
import pymongo
import mitmproxy
from mitmproxy import ctx
import json
class Counter(object):
"""docstring for Counter"""
def __init__(self):
self.client = pymongo.MongoClient("localhost")
self.db=self.client.igetget
self.collection = self.db.books
def updated_book(self,data):
self.collection.insert(data)
Counter=Counter()
def response(flow):
global collection
ctx.log.info("-----------")
url="https://entree.igetget.com/ebook2/v1/ranklist/list?count="
#可以根据自己想要爬的链接换上
if flow.request.url.startswith(url):
text=flow.response.text
data=jso