mitmproxy使用

最近爬取微信時需要用到mitmproxy, 所以就瞭解了下, 下面是使用的一些過程


def response(flow):
    http_request = flow.request
    http_response = flow.response
    current_url = http_request.url
    cookies = http_request.cookies
    logger.info('wx_uin: %s' % cookies.get('wxuin'))
    logger.info('biz_id: %s' % http_request.query.get('__biz'))
    if http_response.status_code != 200:
        return
    func_dict = {
        'weixin.qq.com/mp/profile_ext?action=home': HomeHandler,
        'weixin.qq.com/mp/profile_ext?action=getmsg': ScrollHandler
    }
    for (key, value) in func_dict.items():
        if key in current_url:
            try:
                handler = value(http_request, http_response)
                result = handler.run()
            except NotFoundPublicAccount as e:
                flow.response.text = e.result
            except Exception as e:
                logger.error(e)
            else:
                if result:
                    flow.response.text = result
            break

啓動

mitmdump -s proxy.py -p 8888

在手機代理即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章