Python:mitmproxy获取HTTP请求URL

import mitmproxy.http
import logging,sys

logging.basicConfig(filename=sys.path[0]+'/'+__name__+'.log',format='[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]', level=logging.INFO,filemode='a',datefmt='%Y-%m-%d%I:%M:%S %p')

# http static resource file extension
static_ext = ['js', 'css', 'ico', 'jpg', 'png', 'gif', 'jpeg', 'bmp', 'conf']
# media resource files type
media_types = ['image', 'video', 'audio']

# url filter
url_filter = ['www.baidu.com','m.baidu.com','mbd.baidu.com','www.google.com','www.qq.com','www.youku.com','h5.dingtalk.com']

word_filter = ['json','JSON','login','error']

static_files = [
    'text/css',
    'image/jpeg',
    'image/gif',
    'image/png',
]


# 词过滤
def wordFilter(url):
    flag = False
    for word in word_filter:
        if url.__contains__(word):
            flag = True
            break
    return flag


class HttpFilter:
    def response(self, flow: mitmproxy.http.HTTPFlow):
        # 忽略相应的地址
        host = flow.request.host
        if host in url_filter:
            return

        if not flow.request.method == "GET":
            return

        if not flow.response.status_code == 200:
            return

        # 忽略相应的请求
        url = flow.request.url
        if wordFilter(url):
            return
        lastPath = url.split('?')[0].split('/')[-1]
        if lastPath.split('.')[-1] in static_ext:
            return

        if flow.response.text.__contains__('

 

你可能感兴趣的:(脚本,Python,mitmproxy)