720 lines
33 KiB
Python
720 lines
33 KiB
Python
import datetime
|
|
import time
|
|
import re
|
|
|
|
from sqlalchemy import create_engine, text
|
|
from sqlalchemy.orm import sessionmaker
|
|
from urllib.parse import quote_plus
|
|
import jsonpath
|
|
from mitmproxy.tools.main import mitmdump
|
|
import json,socket,os
|
|
from winproxy import ProxySetting
|
|
from 药店.run3_请求render import newsetting
|
|
|
|
pwd = quote_plus("@7646!")
|
|
DB_URL = f"mysql+pymysql://root:Aliyun{pwd}@183.6.7.91:23016/headers_project?charset=utf8mb4"
|
|
engine = create_engine(
|
|
DB_URL,
|
|
pool_size=10,
|
|
max_overflow=20,
|
|
pool_recycle=3600,
|
|
echo=False
|
|
)
|
|
SessionLocal = sessionmaker(bind=engine, expire_on_commit=False)
|
|
tent = newsetting.All_Setting('183.6.7.91', 23016, 'headers_project')
|
|
tent2 = newsetting.All_Setting('183.6.7.91', 33016, 'tk_hotel')
|
|
menu_buffer = {}
|
|
|
|
|
|
# with open('H5guard.js','r',encoding='utf-8') as f:
|
|
# con = f.read()
|
|
|
|
def get_id(data):
|
|
poi_id = data['url'].split('/poi/')[1].split('?')[0]
|
|
vals_a = jsonpath.jsonpath(data, '$..poi_id_str') or []
|
|
vals_b = jsonpath.jsonpath(data, '$..wm_poi_view_id') or []
|
|
a = str(vals_a[0]) if vals_a else None
|
|
b = str(vals_b[0]) if vals_b else None
|
|
if a is None:
|
|
m = re.search(r'"poi_id_str"\s*:\s*"([^"]+)"', json.dumps(data, ensure_ascii=False))
|
|
a = m.group(1) if m else ""
|
|
if b is None:
|
|
m = re.search(r'"wm_poi_view_id"\s*:\s*"([^"]+)"', json.dumps(data, ensure_ascii=False))
|
|
b = m.group(1) if m else ""
|
|
print((a, b))
|
|
with engine.begin() as conn:
|
|
conn.execute(text(
|
|
"""
|
|
CREATE TABLE IF NOT EXISTS id_num_str (
|
|
id_num VARCHAR(255) NOT NULL,
|
|
id_str VARCHAR(155) NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
|
"""
|
|
))
|
|
conn.execute(
|
|
text("INSERT INTO id_num_str (id_num, id_str) VALUES (:id_num, :id_str)"),
|
|
{"id_num": poi_id, "id_str": a}
|
|
)
|
|
|
|
def set_proxy():
|
|
# mac系统这段代码可以删除
|
|
ps = ProxySetting()
|
|
"""设置系统代理"""
|
|
ps.enable = True
|
|
ps.server = '127.0.0.1:8080'
|
|
ps.registry_write()
|
|
print('代理已经打开!')
|
|
|
|
|
|
def send_socket(da):
|
|
# 这个可以删除
|
|
a2 = json.dumps(da)
|
|
a3 = a2.encode()
|
|
s = socket.socket()
|
|
s.connect(('localhost', 12354))
|
|
s.sendall(a3)
|
|
s.close()
|
|
|
|
|
|
def get_script_path(script_name):
|
|
# 保留定位用
|
|
scriptpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), script_name)
|
|
print(os.path.join(os.path.dirname(os.path.abspath(__file__)), script_name))
|
|
return scriptpath
|
|
|
|
|
|
|
|
def reqdata(url2):
|
|
data = {}
|
|
# print(url2)
|
|
for i in url2.split('&'):
|
|
key = i.split('=')[0]
|
|
value = i.split('=')[1]
|
|
data[key] = value
|
|
print(f'"{key}":"{value}",')
|
|
|
|
return data
|
|
|
|
def get_headers(headers):
|
|
headers2 = {}
|
|
for header, value in headers.items():
|
|
print(f"{header}: {value}")
|
|
headers2[header] = value
|
|
return headers2
|
|
# R5CTC17ZN2X
|
|
|
|
def choose2_api(url):
|
|
# 把你需要的url 放入列表
|
|
target_url = [
|
|
'https://wx.waimai.meituan.com/weapp/v11/search/globalpage',
|
|
"https://hcapi-wx.waimai.meituan.com/wxapp/v1/poi/product/smooth/render",#外卖_买药_poi_render
|
|
"https://hcapi-wx.waimai.meituan.com/wxapp/v1/poi/sputag/products",#外卖_买药_poi_products
|
|
"https://hcapi-wx.waimai.meituan.com/wxapp/v1/poi/food",#外卖_买药_poi_food
|
|
|
|
"https://wx-shangou.meituan.com/wxapp/v1/poi/product/smooth/render",#外卖_便利店_poi_render
|
|
"https://wx-shangou.meituan.com/wxapp/v1/poi/sputag/products",#外卖_便利店_poi_products
|
|
"https://wx-shangou.meituan.com/wxapp/v1/poi/food",#外卖_便利店_poi_food
|
|
|
|
"https://hcapi-wx.waimai.meituan.com/mtweapp/v1/poi/product/smooth/render",#美团_买药_poi_render
|
|
"https://hcapi-wx.waimai.meituan.com/mtweapp/v1/poi/sputag/products",#美团_买药_poi_products
|
|
"https://hcapi-wx.waimai.meituan.com/mtweapp/v1/poi/food",#美团_买药_poi_food
|
|
|
|
"https://wx-shangou.meituan.com/mtweapp/v1/poi/product/smooth/render",#美团_便利店poi_render
|
|
"https://wx-shangou.meituan.com/mtweapp/v1/poi/sputag/products",#美团_便利店poi_products
|
|
"https://wx-shangou.meituan.com/mtweapp/v1/poi/food",#美团_便利店poi_food
|
|
|
|
"https://hcapi-wx.waimai.meituan.com/quickbuy/v1/poi/product/smooth/render",#闪购_买药poi_render
|
|
"https://hcapi-wx.waimai.meituan.com/quickbuy/v1/poi/sputag/products",#闪购_买药poi_products
|
|
"https://hcapi-wx.waimai.meituan.com/quickbuy/v1/poi/food",#闪购_买药poi_food
|
|
|
|
"https://wx-shangou.meituan.com/quickbuy/v1/poi/product/smooth/render",#闪购_便利店_poi_render
|
|
"https://wx-shangou.meituan.com/quickbuy/v1/poi/sputag/products",#闪购_便利店_poi_products
|
|
"https://wx-shangou.meituan.com/quickbuy/v1/poi/food",#闪购_便利店_poi_food
|
|
|
|
'https://wx.waimai.meituan.com/weapp/v1/poi/food', # 美团美食food
|
|
'https://wx.waimai.meituan.com/weapp/v1/poi/info', # 美团美食info
|
|
'https://wx.waimai.meituan.com/weapp/shop/v1/poi/productlist', # 美团美食productlist
|
|
'https://wx.waimai.meituan.com/weapp/poi/food/render', # 美团美食rende
|
|
'https://ihotel.meituan.com/coresearch/v2/hotel/list',
|
|
'https://ihotel.meituan.com/group/v1/poi/',
|
|
'https://wx.waimai.meituan.com/weapp/v1/food/payattention',
|
|
'https://wx.waimai.meituan.com/weapp/v1/user/favorite/getmyfavorite',
|
|
'https://i.waimai.meituan.com/openh5/user/queryFavorite',
|
|
'https://ihotel.meituan.com/hbsearch/v4/deal/search/suggest',
|
|
"https://i.waimai.meituan.com/external/ajax/poi/",
|
|
"https://i.waimai.meituan.com/openh5/poi/info?",
|
|
"https://ihotel.meituan.com/naruto/hotel/core/router/shelf", # 美团酒店详情1
|
|
"https://ihotel.meituan.com/productapi/v3/prepayList", # 美团酒店详情2
|
|
"https://mall.meituan.com/api/c/poi", # 小象超市程序分类
|
|
"https://hcapi-wx.waimai.meituan.com/storm/graphql/tile/query/from_app_drug_detail", # 美团药店商品详情
|
|
"https://wx-shangou.meituan.com/mtweapp/v2/poi/product/info", # 便利店商品详情原始优化包
|
|
]
|
|
for b in target_url:
|
|
if b in url:
|
|
print('*********hit************')
|
|
print(url)
|
|
return True
|
|
return False
|
|
|
|
def insert_sql(table_name,da):
|
|
sql = """INSERT INTO {table_name}
|
|
(dfpid, ip, json_data, title, channel, is_ok, req_count)
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
|
ON DUPLICATE KEY UPDATE
|
|
json_data = VALUES(json_data), is_ok = null""".format(table_name=table_name)
|
|
print(sql,da)
|
|
tent.write_data_one(sql, da)
|
|
|
|
def insert_sql2(table_name,da):
|
|
sql = """INSERT INTO {table_name}
|
|
(dfpid, ip, json_data, title, channel, is_ok, req_count)
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s)
|
|
ON DUPLICATE KEY UPDATE
|
|
json_data = VALUES(json_data), is_ok = null""".format(table_name=table_name)
|
|
tent2.write_data_one(sql, da)
|
|
|
|
|
|
|
|
def rec_headers(url,headers,data,title,ip_address):
|
|
dfpid = eval(headers['mtgsig'])['a3']+title
|
|
out_data = (url,headers,data)
|
|
if '/v1/poi/product/smooth/render' in url:
|
|
channel = 'render'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('market_render_headers', da)
|
|
elif '/v1/poi/sputag/products' in url:
|
|
channel = 'products'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('market_products_headers', da)
|
|
|
|
elif '/v1/poi/food' in url:
|
|
channel = 'food'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('market_food_headers', da)
|
|
elif '/naruto/hotel/core/router/shelf' in url or 'productapi/v3/prepayList' in url:
|
|
channel = 'hotel'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('hotel_hd', da)
|
|
elif "https://hcapi-wx.waimai.meituan.com/storm/graphql/tile/query/from_app_drug_detail" in url:
|
|
channel = 'item'
|
|
title = '便利店商品详情原始优化包'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('medince_item_hd', da)
|
|
elif "https://wx-shangou.meituan.com/mtweapp/v2/poi/product/info" in url:
|
|
channel = 'newretail'
|
|
da = (dfpid,ip_address,json.dumps(out_data,ensure_ascii=False),title,channel,None,0)
|
|
insert_sql('medince_item_hd', da)
|
|
|
|
elif '/v1/food/payattention' in url:
|
|
channel = 'payattention'
|
|
da = (dfpid, ip_address, json.dumps(out_data, ensure_ascii=False), title, channel, None, 0)
|
|
print(da)
|
|
insert_sql('market_payattention_hd', da)
|
|
|
|
|
|
|
|
|
|
def rec_meishi(da,channel_name):
|
|
order_name, wm_ctype, dfpid, ip_address, json_data = da
|
|
sql1 = f"select id from meishi_headers where dfpid = '{dfpid}'"
|
|
kk = tent.get_shoppingmalls(sql1)
|
|
if channel_name == 'food':
|
|
if bool(kk) is False:
|
|
insert_sql = """
|
|
insert into meishi_headers (order_name,wm_ctype,dfpid,ip_address,food_data) values (%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE
|
|
food_data = VALUES(food_data);
|
|
"""
|
|
tent.write_data_one(insert_sql,da)
|
|
else:
|
|
idd = kk[0][0]
|
|
update_sql = f"""
|
|
update meishi_headers set food_data = '{json_data}' where id = {idd}
|
|
"""
|
|
tent.update_data(update_sql)
|
|
|
|
elif channel_name == 'products':
|
|
if bool(kk) is False:
|
|
insert_sql = """
|
|
insert into meishi_headers (order_name,wm_ctype,dfpid,ip_address,products_data) values (%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE
|
|
food_data = VALUES(food_data);
|
|
"""
|
|
tent.write_data_one(insert_sql,da)
|
|
else:
|
|
idd = kk[0][0]
|
|
update_sql = f"""
|
|
update meishi_headers set products_data = '{json_data}' where id = {idd}
|
|
"""
|
|
tent.update_data(update_sql)
|
|
|
|
pass
|
|
elif channel_name == 'render':
|
|
if bool(kk) is False:
|
|
insert_sql = """
|
|
insert into meishi_headers (order_name,wm_ctype,dfpid,ip_address,render_data) values (%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE
|
|
food_data = VALUES(food_data);
|
|
"""
|
|
tent.write_data_one(insert_sql,da)
|
|
else:
|
|
idd = kk[0][0]
|
|
update_sql = f"""
|
|
update meishi_headers set render_data = '{json_data}' where id = {idd}
|
|
"""
|
|
tent.update_data(update_sql)
|
|
|
|
pass
|
|
|
|
def response(flow):
|
|
false = ''
|
|
null = ''
|
|
true = ''
|
|
if flow.request.headers.get('Upgrade', '').lower() == 'websocket' and 'wpush.meituan.com/websocket/' in flow.request.url:
|
|
# 拒绝websocket
|
|
# 这里可以修改返回的状态码和原因,默认是403 Forbidden
|
|
flow.response = flow.response
|
|
flow.response.status_code = 403
|
|
flow.response.reason = 'Forbidden'
|
|
# 结束流,不再转发请求
|
|
flow.kill(flow.response)
|
|
# if "https://appsec-mobile.meituan.com/h5guard/H5guard.js" in flow.request.url or "https://s3plus.meituan.net/v1/mss_e6aa2b2c35b3432988a7a61f7ed79d37/h5guard/H5guard.js" in flow.request.url:
|
|
# # 替换原始响应体
|
|
# print('找到替换的目标')
|
|
# flow.response.text = con
|
|
# # 确保设置正确的 Content-Type 头
|
|
# flow.response.headers["Content-Type"] = "application/javascript"
|
|
|
|
if 'https://h5.waimai.meituan.com/waimai/mindex/menu?' in flow.request.url or 'https://cactivityapi-sc.waimai.meituan.com/' in flow.request.url or 'https://yiyao-h5.meituan.com/web/merchantQualification.html?' in flow.request.url or 'https://meishi.meituan.com/meishi/poi/index.html?' in flow.request.url or 'https://titan-ws.pinduoduo.com' in flow.request.url:
|
|
# js注入
|
|
print(flow.request.url)
|
|
if flow.response.headers.get('Content-Type', '').startswith('text/html'):
|
|
# 注入JavaScript代码
|
|
|
|
js_code = """
|
|
<script>
|
|
alert('MARKET_程序启动正常,可以准备开始');
|
|
!(function () {
|
|
// 获取dfpid
|
|
function getCookieValue(cookieName) {
|
|
const cookies = document.cookie.split('; ');
|
|
for (let item of cookies) {
|
|
if (item.includes(cookieName)) {
|
|
// 对命中的 item 进行切分,并返回第 0 个部分的值
|
|
const keyValuePair = item.split('-')[0]; // 先切分 "-"
|
|
return keyValuePair.split('=')[1]; // 再切分 "=",取值部分
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 调用函数并获取 "WEBDFPID" 的值
|
|
|
|
const result = getCookieValue("WEBDFPID");
|
|
|
|
const targetClientId = result+'_pc'
|
|
console.log(targetClientId); // 输出:abcdefg
|
|
|
|
// WebSocket 连接
|
|
const ws = new WebSocket('wss://mtworker.tech:5003/');
|
|
|
|
// 连接成功建立的回调方法
|
|
ws.onopen = function (event) {
|
|
console.log("Connected to server");
|
|
ws.send(result+"_web"); // 发送客户端ID
|
|
};
|
|
|
|
// 接收消息的回调方法
|
|
ws.onmessage = function (event) {
|
|
console.log(event.data);
|
|
|
|
let _data1 = event.data;
|
|
let _data2 = JSON.parse(_data1);
|
|
let _data3 = _data2.datas;
|
|
let _data4 = JSON.parse(_data3);
|
|
|
|
console.log(typeof (_data4));
|
|
console.log(_data4);
|
|
|
|
// 调用函数获取 mtgsig 值
|
|
let mtg = getValue(_data4);
|
|
let cook = document.cookie;
|
|
let ua = window.navigator.userAgent;
|
|
// 构造返回数据
|
|
let rt_data = {
|
|
cookie: cook,
|
|
userAgent: ua,
|
|
mtgsig: mtg,
|
|
};
|
|
|
|
// 将消息和目标客户端 ID 拼接成字符串格式:targetClientId:message
|
|
let messageWithTarget = `${targetClientId}:${JSON.stringify(rt_data)}`;
|
|
ws.send(messageWithTarget); // 发送消息到目标客户端
|
|
};
|
|
|
|
// 连接关闭的回调方法
|
|
ws.onclose = function (event) {
|
|
console.log("Disconnected from server");
|
|
};
|
|
|
|
// 获取 mtgsig 值的函数
|
|
function getValue(daa) {
|
|
H5guard.initWithKey({ appKey:'dcf7c9fd764e553cf16d99551f67c92916edf992353a0c37b8359eba19d53524'});
|
|
var mts2 = H5guard.sign(daa);
|
|
console.log(daa);
|
|
return daa;
|
|
}
|
|
})();
|
|
</script>
|
|
"""
|
|
flow.response.content = flow.response.content.replace(b'</head>', js_code.encode('utf-8') + b'</head>')
|
|
|
|
url = (flow.request.url)
|
|
t2 = choose2_api(url)
|
|
client_info = {
|
|
"ip": flow.client_conn.address[0],
|
|
"port": flow.client_conn.address[1],
|
|
"tls_version": getattr(flow.client_conn.tls_version, "name", None),
|
|
"cipher": getattr(flow.client_conn.cipher, "name", None),
|
|
"timestamp": flow.client_conn.timestamp_start
|
|
}
|
|
# print(client_info)
|
|
if t2:
|
|
headers = dict(flow.request.headers)
|
|
data = flow.request.content
|
|
data2 = data.decode('utf8')
|
|
if flow.request.method == "POST":
|
|
data3 = reqdata(data2)
|
|
else:
|
|
data3 = data2
|
|
req2 = flow.response.content
|
|
req = req2.decode('utf-8')
|
|
if not ("https://ihotel.meituan.com/productapi/v3/prepayList" in url or "https://ihotel.meituan.com/naruto/hotel/core/router/shelf" in url):
|
|
ress = json.loads(req)
|
|
title = url.split('?')[0].split('/')[-1]
|
|
ip_address = client_info['ip']
|
|
dfpid = eval(headers['mtgsig'])['a3']
|
|
|
|
print(dfpid)
|
|
if 'https://hcapi-wx.waimai.meituan.com/wxapp/' in url:
|
|
# 外卖买药接口
|
|
title = '外卖-买药接口'
|
|
print(title)
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
elif 'https://hcapi-wx.waimai.meituan.com/quickbuy/' in url:
|
|
# 闪购买药接口
|
|
title = '闪购-买药接口'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
elif 'https://hcapi-wx.waimai.meituan.com/mtweapp' in url:
|
|
# 美团买药接口
|
|
title = '美团-买药接口'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
if 'https://wx-shangou.meituan.com/wxapp/' in url:
|
|
# 外卖小程序便利店
|
|
title = '外卖-美团_便利店'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
|
|
|
|
elif 'https://wx-shangou.meituan.com/mtweapp/' in url:
|
|
# 美团便利店
|
|
title = '美团-美团_便利店'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
|
|
|
|
|
|
elif 'https://wx-shangou.meituan.com/quickbuy/' in url:
|
|
# 闪购-美团_便利店
|
|
title = '闪购-美团_便利店'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
#
|
|
#
|
|
#
|
|
if 'https://wx.waimai.meituan.com/weapp/v1/poi/food' in url:
|
|
k = menu_buffer.get(dfpid, {})
|
|
k['food'] = (headers, flow.request.url, data3)
|
|
menu_buffer[dfpid] = k
|
|
if 'food' in k and 'productlist' in k and 'render' in k:
|
|
das = (k['food'], k['productlist'], k['render'])
|
|
da = (dfpid, json.dumps(das), 0)
|
|
# and is_ok = null
|
|
sql = """
|
|
insert into menu_hd (title, hd_data, count_req) values (%s, %s, %s) on duplicate key update hd_data = values(hd_data), is_ok = null
|
|
"""
|
|
tent.write_data_one(sql, da)
|
|
|
|
|
|
|
|
|
|
elif 'https://wx.waimai.meituan.com/weapp/shop/v1/poi/productlist' in url:
|
|
k = menu_buffer.get(dfpid, {})
|
|
k['productlist'] = (headers, flow.request.url, data3)
|
|
menu_buffer[dfpid] = k
|
|
if 'food' in k and 'productlist' in k and 'render' in k:
|
|
das = (k['food'], k['productlist'], k['render'])
|
|
da = (dfpid, json.dumps(das), 0)
|
|
sql = """
|
|
insert into menu_hd (title, hd_data, count_req) values (%s, %s, %s) on duplicate key update hd_data = values(hd_data)
|
|
"""
|
|
tent.write_data_one(sql, da)
|
|
|
|
|
|
|
|
|
|
elif 'https://wx.waimai.meituan.com/weapp/poi/food/render' in url:
|
|
k = menu_buffer.get(dfpid, {})
|
|
k['render'] = (headers, flow.request.url, data3)
|
|
menu_buffer[dfpid] = k
|
|
if 'food' in k and 'productlist' in k and 'render' in k:
|
|
das = (k['food'], k['productlist'], k['render'])
|
|
da = (dfpid, json.dumps(das), 0)
|
|
sql = """
|
|
insert into menu_hd (title, hd_data, count_req) values (%s, %s, %s) on duplicate key update hd_data = values(hd_data)
|
|
"""
|
|
tent.write_data_one(sql, da)
|
|
|
|
# elif 'https://wx.waimai.meituan.com/weapp/' in url:
|
|
# format_today = str(datetime.date.today()).replace('-', '')
|
|
# channel = '美食' + format_today
|
|
# out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data3,
|
|
# 'channel': channel,
|
|
# 'request': ress}
|
|
# path = os.path.join(r'headers_data',channel,dfpid,title)
|
|
# if os.path.exists(path) is False:
|
|
# os.makedirs(path)
|
|
# with open(f'{path}/{title}','w',encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
elif 'https://wx.waimai.meituan.com/weapp/v1/poi/info' in url:
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = '店铺详情' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data3,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data',channel,dfpid,title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}','w',encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
|
|
elif 'https://wx.waimai.meituan.com/weapp/v1/poi/info' in url:
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = '店铺详情' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data3,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data',channel,dfpid,title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}','w',encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
|
|
elif 'https://wx.waimai.meituan.com/weapp/v11/search/globalpage' in url:
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = '美食search' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data3,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data',channel,dfpid,title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}','w',encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
hd = (headers, flow.request.url, data3)
|
|
da = (dfpid, json.dumps(hd), 0)
|
|
sql = """
|
|
insert into search_globalpage_hd (title,hd_data,count_req) values (%s,%s,%s)
|
|
on duplicate key update hd_data = values(hd_data), is_ok = null
|
|
"""
|
|
tent.write_data_one(sql, da)
|
|
|
|
if "https://ihotel.meituan.com/productapi/v3/prepayList" in url or "https://ihotel.meituan.com/naruto/hotel/core/router/shelf" in url:
|
|
title = '美团酒店详情'
|
|
rec_headers(url, headers, data2, title, ip_address)
|
|
|
|
if "https://hcapi-wx.waimai.meituan.com/storm/graphql/tile/query/from_app_drug_detail" in url:
|
|
title = '美团药店商品详情'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
if flow.request.method == "GET" or flow.request.method == "POST":
|
|
if "https://i.waimai.meituan.com/external/ajax/poi/" in url:
|
|
headers = dict(flow.request.headers)
|
|
params = dict(flow.request.query)
|
|
data = flow.request.content
|
|
if bool(data):
|
|
data2 = data.decode('utf8')
|
|
else:
|
|
data2 = ''
|
|
req2 = flow.response.content
|
|
status_code = flow.response.status_code
|
|
req = req2.decode('utf-8')
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'params': params,
|
|
'data': data2, 'request': req, 'status_code': status_code}
|
|
# send_socket(out_data)
|
|
order_name = 'yiming'
|
|
|
|
das = (order_name,dfpid,ip_address,json.dumps(out_data,ensure_ascii=False))
|
|
insrt_sql = """
|
|
insert into ajax_shopinfo (order_name,dfpid,ip_address,ajax_poi) values (%s,%s,%s,%s) ON DUPLICATE KEY UPDATE
|
|
ajax_poi = VALUES(ajax_poi),is_ok = null;
|
|
"""
|
|
tent.write_data_one(insrt_sql,das)
|
|
|
|
# title = url.split('?')[0].split('/')[-1]
|
|
# sv = os.path.join('headersdata', title)
|
|
# os.makedirs(sv, exist_ok=True)
|
|
# with open(f'{sv}/{title}', 'w', encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
# print(out_data)
|
|
|
|
elif "https://i.waimai.meituan.com/openh5/poi/info?" in url:
|
|
headers = dict(flow.request.headers)
|
|
params = dict(flow.request.query)
|
|
data = flow.request.content
|
|
if bool(data):
|
|
data2 = data.decode('utf8')
|
|
else:
|
|
data2 = ''
|
|
|
|
req2 = flow.response.content
|
|
status_code = flow.response.status_code
|
|
req = req2.decode('utf-8')
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method,
|
|
'params': params,
|
|
'data': data2, 'request': req, 'status_code': status_code}
|
|
# send_socket(out_data)
|
|
order_name = 'yiming'
|
|
das = (order_name,dfpid,ip_address,json.dumps(out_data,ensure_ascii=False))
|
|
insrt_sql = """
|
|
insert into ajax_shopinfo (order_name,dfpid,ip_address,shopinfo) values (%s,%s,%s,%s) ON DUPLICATE KEY UPDATE
|
|
shopinfo = VALUES(shopinfo),is_ok = null;
|
|
"""
|
|
tent.write_data_one(insrt_sql,das)
|
|
# title = url.split('?')[0].split('/')[-1]
|
|
# sv = os.path.join('headersdata', title)
|
|
# os.makedirs(sv, exist_ok=True)
|
|
# with open(f'{sv}/{title}', 'w', encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
# print(out_data)
|
|
|
|
|
|
# if 'https://ihotel.meituan.com/core/searchapi/hotel/list' in url:
|
|
# title = '酒店'
|
|
# # rec_headers(url, headers, data3, title, ip_address)
|
|
# format_today = str(datetime.date.today()).replace('-', '')
|
|
# channel = 'hotel_hd' + format_today
|
|
# out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
# 'channel': channel,
|
|
# 'request': ress}
|
|
# path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
# if os.path.exists(path) is False:
|
|
# os.makedirs(path)
|
|
# with open(f'{path}/{title}+3', 'w', encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
|
|
|
|
# if "https://i.waimai.meituan.com/external/ajax/poi/" in url:
|
|
# title = '置换'
|
|
# # rec_headers(url, headers, data3, title, ip_address)
|
|
# out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
# 'request': ress}
|
|
# get_id(out_data)
|
|
# "https://ihotel.meituan.com/coresearch/v2/hotel/list?yodaReady\u003dwx\u0026csecappid\u003dwx7649daed8f2335c4\u0026csecplatform\u003d3\u0026csecversionname\u003d8.0.64\u0026csecversion\u003d1.4.0\u0026openId\u003dodPDr0HGJ2BdrH2WVzcERxshzyRc\u0026antiRepPlatform\u003dAndroid\u0026programName\u003dhotel\u0026utm_medium\u003dWEIXINPROGRAM\u0026riskLevel\u003d71\u0026optimusCode\u003d10\u0026openIdCipher\u003dAwQAAABJAgAAAAEAAAAyAAAAPLgC95WH3MyqngAoyM%2Fhf1hEoKrGdo0pJ5DI44e1wGF9AT3PH7Wes03actC2n%2FGVnwfURonD78PewMUppAAAADhllv2jYeNx9yCsaM0v5v6AKYERzOkSQy2JFZytQ8nFF9LiMZ85YCRcOFNUFx5jELO%2FHBPnRkMqew%3D%3D\u0026utm_campaign\u003dentry%253DMTHotel_scene%253D1106\u0026token\u003dAgF0INyYVIZwWhw1NKumpDfk0w_ASCcoq1NP7Tgf7gQQQGGcMcyRqqns-CKBnWYCGGFVfQaRWS7FRwAAAACXLwAASZknfjhzabVI9i97U8UWMhMV5U66I4vc9qeTZJwVuGHoN_llNPDFgSmCPTgANP37\u0026usertoken\u003dAgF0INyYVIZwWhw1NKumpDfk0w_ASCcoq1NP7Tgf7gQQQGGcMcyRqqns-CKBnWYCGGFVfQaRWS7FRwAAAACXLwAASZknfjhzabVI9i97U8UWMhMV5U66I4vc9qeTZJwVuGHoN_llNPDFgSmCPTgANP37\u0026userToken\u003dAgF0INyYVIZwWhw1NKumpDfk0w_ASCcoq1NP7Tgf7gQQQGGcMcyRqqns-CKBnWYCGGFVfQaRWS7FRwAAAACXLwAASZknfjhzabVI9i97U8UWMhMV5U66I4vc9qeTZJwVuGHoN_llNPDFgSmCPTgANP37\u0026userId\u003d5712038078\u0026userid\u003d5712038078\u0026uuid\u003d19aed98f648c8-1a3eb7beb6a992-0-0-19aed98f648c8\u0026locateCityId\u003d20\u0026locatecityid\u003d20\u0026appMiniVersion\u003d8.90.1\u0026lat\u003d23.1\u0026lng\u003d113.3\u0026appletShieldScene\u003dnull\u0026hotelStar\u003d\u0026price\u003d\u0026cityId\u003d20\u0026ci\u003d20\u0026channelCityId\u003d20\u0026gps_cityid\u003d20\u0026antiRepCityId\u003d20\u0026antiRepLocateCityId\u003d20\u0026category\u003d5\u0026client\u003dandroid\u0026cateId\u003d20\u0026cate\u003d20\u0026attr_28\u003d129\u0026version_name\u003d9.14.800\u0026mypos\u003d23.1%2C113.3\u0026sourceType\u003dhotelSearch\u0026wechatVersion\u003d8.0.64\u0026sdkVersion\u003d3.11.3\u0026startDay\u003d20251205\u0026endDay\u003d20251205\u0026magicMemberCode\u003d1105%2C1106\u0026offset\u003d0\u0026q\u003d%E5%B9%BF%E5%B7%9E%E5%A1%94\u0026cellTagType\u003d1\u0026limit\u003d6\u0026hotelCustomGpsStatus\u003d1\u0026specialDealHotelScene\u003dtrue\u0026riskPlatform\u003d13\u0026channelSelectCityId\u003d20\u0026appletVersionName\u003d9.11.1721\u0026appletAppId\u003dwx7649daed8f2335c4\u0026utm_fp\u003dMINI_PROGRAM\u0026SDKVersion\u003d3.11.3"
|
|
if 'https://ihotel.meituan.com/coresearch/v2/hotel/list' in url:
|
|
title = '酒店'
|
|
# rec_headers(url, headers, data3, title, ip_address)
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = 'hotel_hd' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}+3', 'w', encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
#
|
|
# elif 'https://ihotel.meituan.com/hbsearch/v4/deal/search/suggest' in url:
|
|
# title = '酒店关键字搜索'
|
|
# # rec_headers(url, headers, data3, title, ip_address)
|
|
# format_today = str(datetime.date.today()).replace('-', '')
|
|
# channel = 'hotel_hd' + format_today
|
|
# out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
# 'channel': channel,
|
|
# 'request': ress}
|
|
# path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
# if os.path.exists(path) is False:
|
|
# os.makedirs(path)
|
|
# with open(f'{path}/{title}', 'w', encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
# if 'https://ihotel.meituan.com/producctapi/v3/prepayList' in url:
|
|
# title = '美团酒店详情'
|
|
# # rec_headers(url, headers, data3, title, ip_address)
|
|
# format_today = str(datetime.date.today()).replace('-', '')
|
|
# channel = 'hotel_hd' + format_today
|
|
# out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
# 'channel': channel,
|
|
# 'request': ress}
|
|
# path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
# if os.path.exists(path) is False:
|
|
# os.makedirs(path)
|
|
# with open(f'{path}/{title}', 'w', encoding='utf-8') as f:
|
|
# f.write(json.dumps(out_data))
|
|
if 'https://ihotel.meituan.com/group/v1/poi/' in url:
|
|
title = '美团酒店列表'
|
|
# rec_headers(url, headers, data3, title, ip_address)
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = 'hotel_hd' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}', 'w', encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
|
|
if 'https://wx.waimai.meituan.com/weapp/v1/food/payattention' in url:
|
|
title = '收藏'
|
|
rec_headers(url, headers, data3, title, ip_address)
|
|
|
|
elif 'https://i.waimai.meituan.com/openh5/user/queryFavorite' in url or 'https://wx.waimai.meituan.com/weapp/v1/user/favorite/getmyfavorite' in url:
|
|
title = '收藏列表'
|
|
# rec_headers(url, headers, data3, title, ip_address)
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = 'getmyfavorite' + format_today
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data2,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data', channel, dfpid, title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}+{str(time.time())}', 'w', encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
|
|
elif '/sku/list/category/v8' in url:
|
|
format_today = str(datetime.date.today()).replace('-', '')
|
|
channel = '小象超市' + format_today
|
|
match = re.search(r'__reqTraceID=([^&]+)', flow.request.url)
|
|
req_trace_id = match.group(1)
|
|
title = req_trace_id
|
|
|
|
print(f"提取到的 __reqTraceID 为: {req_trace_id}")
|
|
out_data = {'headers': headers, 'url': flow.request.url, 'method': flow.request.method, 'data': data3,
|
|
'channel': channel,
|
|
'request': ress}
|
|
path = os.path.join(r'headers_data',channel,dfpid,title)
|
|
if os.path.exists(path) is False:
|
|
os.makedirs(path)
|
|
with open(f'{path}/{title}','w',encoding='utf-8') as f:
|
|
f.write(json.dumps(out_data))
|
|
|
|
# getmyfavorite
|
|
|
|
|
|
def run():
|
|
|
|
mitmdump(["-s",__file__,"-q","-m","socks5@2080","-m","regular@8080"])#修改代码
|
|
|
|
if __name__ == '__main__':
|
|
set_proxy()
|
|
run() |