upload
This commit is contained in:
@@ -11,12 +11,62 @@ from 酒店任务拿交 import get_one_task, upload_one_task
|
||||
import newsetting as ten
|
||||
|
||||
tent = ten.All_Setting(host='183.6.7.91', port=33016, db='mt_hotel')
|
||||
tent2 = ten.All_Setting(host='183.6.7.91', port=33016, db='headers_project')
|
||||
tent2 = ten.All_Setting(host='192.168.5.2', port=3307, db='headers_project')
|
||||
# proxy = {"http": None, "https": None}
|
||||
import pymysql
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, Optional
|
||||
|
||||
import sys
|
||||
# 本地出签(Node 补环境跑小程序 jsguard),实现在 mjz\小程序逆向\AI代码\小程序mtgsig.py
|
||||
sys.path.insert(0, r'C:\Users\mjz\Desktop\python\mjz\小程序逆向\AI代码')
|
||||
from 小程序mtgsig import get_mtgsig,get_h5_mtgsig_pure
|
||||
|
||||
# 代理出口城市 -> (lat, lng),1位小数,向真机抓包精度看齐(真机广州=23.1,113.3 已验证)
|
||||
# 用途:get_prox 返回代理出口城市后,按城市名取对应坐标,让 lat/lng 与 IP 出口地同源
|
||||
CITY_GPS = {
|
||||
"苏州": ("31.3", "120.6"),
|
||||
"佛山": ("23.0", "113.1"),
|
||||
"长沙": ("28.2", "112.9"),
|
||||
"武汉": ("30.594940", "114.302634"),
|
||||
"杭州": ("30.231471", "120.018594"),
|
||||
"太原": ("37.9", "112.5"),
|
||||
"乌鲁木齐": ("43.8", "87.6"),
|
||||
"上海": ("30.948869", "121.303506"),
|
||||
"重庆": ("29.6", "106.5"),
|
||||
"成都": ("30.6", "104.1"),
|
||||
"南通": ("32.0", "120.9"),
|
||||
"深圳": ("22.545482", "114.055597"),
|
||||
"兰州": ("36.1", "103.8"),
|
||||
"海口": ("20.0", "110.3"),
|
||||
"济南": ("36.7", "117.0"),
|
||||
"南京": ("32.1", "118.8"),
|
||||
"郑州": ("34.7", "113.6"),
|
||||
"福州": ("26.1", "119.3"),
|
||||
"拉萨": ("29.7", "91.1"),
|
||||
"沈阳": ("41.8", "123.4"),
|
||||
"广州": ("23.437968", "113.554650"),
|
||||
"昆明": ("25.0", "102.7"),
|
||||
"北京": ("39.9", "116.4"),
|
||||
"天津": ("39.1", "117.2"),
|
||||
"长春": ("43.9", "125.3"),
|
||||
"西安": ("34.3", "108.9"),
|
||||
"哈尔滨": ("45.8", "126.5"),
|
||||
"贵阳": ("26.6", "106.7"),
|
||||
"银川": ("38.5", "106.2"),
|
||||
"西宁": ("36.616448", "101.775687"),
|
||||
"南昌": ("28.7", "115.9"),
|
||||
"呼和浩特": ("40.8", "111.7"),
|
||||
"石家庄": ("38.0", "114.5"),
|
||||
"南宁": ("22.8", "108.4"),
|
||||
"合肥": ("31.8", "117.2"),
|
||||
"青岛": ("36.1", "120.4"),
|
||||
"东莞": ("23.0", "113.8"),
|
||||
"厦门": ("24.5", "118.1"),
|
||||
"无锡": ("31.5", "120.3"),
|
||||
"大连": ("38.9", "121.6"),
|
||||
}
|
||||
|
||||
|
||||
def clean_and_insert_hotel_booking(
|
||||
raw_data: Dict[str, Any],
|
||||
@@ -210,6 +260,22 @@ def get_sign_new(url, data, dfpid, mtg_origin):
|
||||
return req
|
||||
|
||||
|
||||
def get_sign_new1(url, data, dfpid, mtg_origin,openId):
|
||||
headers = {"content-type": "application/json", "token": "test_sdfio23923ojbedfojgbouqgew4r32dds"}
|
||||
body = {
|
||||
"mtg_origin":mtg_origin,
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "POST",
|
||||
"open_id": openId,# 微信的open_id
|
||||
}
|
||||
# url = "http://124.222.120.219:18003/hz_wm_jym_1008"
|
||||
url = 'http://129.211.12.35:18003/minipro_mt_0206'
|
||||
req = requests.post(url, headers=headers, json=body, proxies={'http': None, 'https': None}, verify=False).text
|
||||
print(req)
|
||||
return req
|
||||
|
||||
def get_sign_new_get(url, data, dfpid, mtg_origin):
|
||||
headers = {"content-type": "application/json", "token": "jksdfhiownefopwef902fsdf"}
|
||||
|
||||
@@ -226,6 +292,22 @@ def get_sign_new_get(url, data, dfpid, mtg_origin):
|
||||
return req
|
||||
|
||||
|
||||
def get_sign_new1_get(url, data, dfpid, mtg_origin,openId):
|
||||
headers = {"content-type": "application/json", "token": "test_sdfio23923ojbedfojgbouqgew4r32dds"}
|
||||
body = {
|
||||
"mtg_origin":mtg_origin,
|
||||
"url": url,
|
||||
"data": data,
|
||||
"dfpid": dfpid,
|
||||
"method": "GET",
|
||||
"open_id": openId,# 微信的open_id
|
||||
}
|
||||
# url = "http://124.222.120.219:18003/hz_wm_jym_1008"
|
||||
url = 'http://129.211.12.35:18003/minipro_mt_0206'
|
||||
req = requests.post(url, headers=headers, json=body, proxies={'http': None, 'https': None}, verify=False).text
|
||||
print(req)
|
||||
return req
|
||||
|
||||
def get_Datatext(dataq):
|
||||
str1 = ''
|
||||
for i in dataq:
|
||||
@@ -250,8 +332,8 @@ class hotel_run:
|
||||
fromOffline = "false"
|
||||
flagshipFilter = "1"
|
||||
needShowNewDiscInfo = "false"
|
||||
lat = "31.819953"
|
||||
lng = "117.221201"
|
||||
lat = "31.820953"
|
||||
lng = "117.222201"
|
||||
ci = "20"
|
||||
channelCityId = "20"
|
||||
hotelCustomGpsStatus = "0"
|
||||
@@ -265,12 +347,23 @@ class hotel_run:
|
||||
|
||||
# proxy = {"http": None,"https": None}
|
||||
def __init__(self):
|
||||
self.proxy = self.get_prox()
|
||||
self.proxy_list = self.get_prox()
|
||||
print(self.proxy_list)
|
||||
|
||||
def run_shelf(self, url, params, headers, data, prox):
|
||||
def run_shelf(self, url, params, headers, data, prox, task):
|
||||
clientid = task['data']['cityName'].replace('市', '')
|
||||
if prox:
|
||||
self.proxy = json.loads(prox)
|
||||
task = get_one_task(self.VENDOR, self.USER, self.PWD, self.clientid)
|
||||
# 查绑定城市对应的美团cityId(用于gps_cityid/locateCityId等定位字段)
|
||||
gps_city_id = self.get_city_id(self.bound_city)
|
||||
if not gps_city_id:
|
||||
print(f"城市 {self.bound_city} 在 area_info 查不到 cityId,跳过")
|
||||
return -1
|
||||
# 绑定城市坐标,businessParams里是字符串("23.1"),顶层data是数字(23.1)
|
||||
city_gps = CITY_GPS.get(self.bound_city)
|
||||
if not city_gps:
|
||||
print(f"城市 {self.bound_city} 在 CITY_GPS 无坐标,跳过")
|
||||
return -1
|
||||
result = clean_and_insert_hotel_booking(task)
|
||||
hotel_info = task["data"]
|
||||
print(result)
|
||||
@@ -282,14 +375,22 @@ class hotel_run:
|
||||
end = int(datetime.strptime(task['data']['checkOutDate'], '%Y-%m-%d').timestamp() * 1000)
|
||||
data['requestParams'][0]['businessParams']['start'] = start
|
||||
data['requestParams'][0]['businessParams']['end'] = end
|
||||
data['requestParams'][0]['businessParams']['cityId'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['channelCityId'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['userCityId'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['appCityId'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['gps_cityid'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['gpsCityid'] = task["data"]["cityId"]
|
||||
data['requestParams'][0]['businessParams']['lat'] = self.lat
|
||||
data['requestParams'][0]['businessParams']['lng'] = self.lng
|
||||
data['requestParams'][0]['businessParams']['cityId'] = task["data"]["cityId"] # 酒店城市组,跟任务走,真机=2332,OK
|
||||
data['requestParams'][0]['businessParams']['channelCityId'] = task["data"]["cityId"] # 酒店城市组,跟任务走,OK
|
||||
data['requestParams'][0]['businessParams']['userCityId'] = task["data"]["cityId"] # 酒店城市组,跟任务走,OK
|
||||
data['requestParams'][0]['businessParams']['appCityId'] = task["data"]["cityId"] # 酒店城市组,跟任务走,OK
|
||||
data['requestParams'][0]['businessParams']['gps_cityid'] = gps_city_id # 用户定位城市组,跟绑定城市走
|
||||
data['requestParams'][0]['businessParams']['gpsCityid'] = gps_city_id # 用户定位城市组,跟绑定城市走
|
||||
data['requestParams'][0]['businessParams']['locateCityId'] = gps_city_id # 用户定位城市组,跟绑定城市走
|
||||
data['requestParams'][0]['businessParams']['locatecityid'] = gps_city_id # 用户定位城市组,跟绑定城市走
|
||||
data['requestParams'][0]['businessParams']['lat'] = city_gps[0] # businessParams里lat是字符串
|
||||
data['requestParams'][0]['businessParams']['lng'] = city_gps[1] # businessParams里lng是字符串
|
||||
# data顶层定位字段:真机里 lat/lng 是数字类型,locateCityId 跟绑定城市走
|
||||
data['lat'] = float(city_gps[0]) # 顶层lat是数字,真机=23.1
|
||||
data['lng'] = float(city_gps[1]) # 顶层lng是数字,真机=113.3
|
||||
data['locateCityId'] = gps_city_id # 顶层定位城市ID,跟绑定城市走
|
||||
data['locatecityid'] = gps_city_id # 顶层定位城市ID小写版,跟绑定城市走
|
||||
data['clientRequestTime'] = int(time.time() * 1000) # 请求级实时时间戳,真机每次变
|
||||
# poi = '1743020617'
|
||||
# data['poiId'] = poi
|
||||
# data['requestParams'][0]['businessParams']['poiId'] = poi
|
||||
@@ -298,18 +399,22 @@ class hotel_run:
|
||||
new_url = build_url(url, params)
|
||||
mtg_origin = eval(headers['mtgsig'])
|
||||
dfpid = mtg_origin['a3']
|
||||
headers['mtgsig'] = get_sign_new(new_url, data2, dfpid, mtg_origin)
|
||||
openId = headers['openId']
|
||||
# headers['mtgsig'] = get_sign_new1(new_url, data2, dfpid, mtg_origin,openId)
|
||||
headers['mtgsig'] = get_mtgsig(new_url, data2, dfpid, mtg_origin,openId)
|
||||
|
||||
# response = requests.post(url, headers=headers, data=data,params=params)
|
||||
response = requests.post(new_url, headers=headers, data=data2, proxies=self.proxy)
|
||||
|
||||
print("response.text[:500]", '-' * 50, response.text[:500])
|
||||
print("response.text", '-' * 50, response.text[:])
|
||||
if '您的网络好像不太给力,请稍后再试' in response.text:
|
||||
return 418
|
||||
if "Unauthorized" in response.text[:500]:
|
||||
return 401
|
||||
res = response.json()
|
||||
upload_one_task(self.VENDOR, self.USER, self.PWD, self.clientid, task, res)
|
||||
upload_one_task(self.VENDOR, self.USER, self.PWD, clientid, task, res)
|
||||
# 从响应里提取 traceId,存到 self 供外部回写 hotel_hd
|
||||
self.last_trace_id = self._find_trace_id(res)
|
||||
sql = '''
|
||||
INSERT INTO `hotel_json`
|
||||
(json_data, poi_id, city_id, hotel_name, city_name, check_in_date, check_out_date)
|
||||
@@ -320,40 +425,56 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
hotel_info.get('cityName'), hotel_info.get('checkInDate'), hotel_info.get('checkOutDate')),))
|
||||
return 1
|
||||
|
||||
def run_prepayList(self, url, params, headers, prox):
|
||||
def run_prepayList(self, url, params, headers, prox, task):
|
||||
clientid = task['data']['cityName'].replace('市', '')
|
||||
if prox:
|
||||
self.proxy = json.loads(prox)
|
||||
task = get_one_task(self.VENDOR, self.USER, self.PWD, self.clientid)
|
||||
gps_city_id = self.get_city_id(self.bound_city)
|
||||
if not gps_city_id:
|
||||
print(f"城市 {self.bound_city} 在 area_info 查不到 cityId,跳过")
|
||||
return -1
|
||||
city_gps = CITY_GPS.get(self.bound_city)
|
||||
if not city_gps:
|
||||
print(f"城市 {self.bound_city} 在 CITY_GPS 无坐标,跳过")
|
||||
return -1
|
||||
result = clean_and_insert_hotel_booking(task)
|
||||
hotel_info = task["data"]
|
||||
print(result)
|
||||
print(task)
|
||||
params['poiId'] = task['data']['hotelId']
|
||||
start = int(datetime.strptime(task['data']['checkInDate'], '%Y-%m-%d').timestamp() * 1000)
|
||||
end = int(datetime.strptime(task['data']['checkOutDate'], '%Y-%m-%d').timestamp() * 1000)
|
||||
start = str(int(datetime.strptime(task['data']['checkInDate'], '%Y-%m-%d').timestamp() * 1000))
|
||||
end = str(int(datetime.strptime(task['data']['checkOutDate'], '%Y-%m-%d').timestamp() * 1000))
|
||||
params['start'] = start
|
||||
params['end'] = end
|
||||
params['gps_cityid'] = task["data"]["cityId"]
|
||||
params['gps_cityid'] = gps_city_id
|
||||
params['locateCityId'] = gps_city_id
|
||||
params['locatecityid'] = gps_city_id
|
||||
params['cityId'] = task["data"]["cityId"]
|
||||
params['ci'] = task["data"]["cityId"]
|
||||
params['channelCityId'] = task["data"]["cityId"]
|
||||
params['channelSelectCityId'] = task["data"]["cityId"]
|
||||
params['lat'] = self.lat
|
||||
params['lng'] = self.lng
|
||||
params['gps_cityid'] = task["data"]["cityId"]
|
||||
params['lat'] = city_gps[0]
|
||||
params['lng'] = city_gps[1]
|
||||
new_url = build_url(url, params)
|
||||
mtg_origin = eval(headers['mtgsig'])
|
||||
dfpid = mtg_origin['a3']
|
||||
headers['mtgsig'] = get_sign_new_get(new_url, '', dfpid, mtg_origin)
|
||||
# headers['mtgsig'] = get_sign_new_get(new_url, '', dfpid, mtg_origin)
|
||||
if 'openId' in headers:
|
||||
openId = headers['openId']
|
||||
else:
|
||||
openId = headers['openid']
|
||||
headers['mtgsig'] = get_sign_new1_get(new_url, '', dfpid, mtg_origin,openId)
|
||||
|
||||
response = requests.get(url, headers=headers, params=params, proxies=self.proxy)
|
||||
response = requests.get(new_url, headers=headers, proxies=self.proxy)
|
||||
|
||||
print("response.text[:500]", '-' * 50, response.text[:500])
|
||||
# print("response.text[:]", '-' * 50, response.text[:])
|
||||
if '您的网络好像不太给力,请稍后再试' in response.text:
|
||||
return 418
|
||||
if "Unauthorized" in response.text[:500]:
|
||||
return 401
|
||||
res = response.json()
|
||||
upload_one_task(self.VENDOR, self.USER, self.PWD, self.clientid, task, res)
|
||||
upload_one_task(self.VENDOR, self.USER, self.PWD, clientid, task, res)
|
||||
self.last_trace_id = self._find_trace_id(res)
|
||||
sql = '''
|
||||
INSERT INTO `hotel_json`
|
||||
(json_data, poi_id, city_id, hotel_name, city_name, check_in_date, check_out_date)
|
||||
@@ -365,54 +486,109 @@ VALUES (%s, %s, %s, %s, %s, %s, %s)
|
||||
return 1
|
||||
|
||||
def get_headers(self):
|
||||
# 取一批可用抓包 headers,主循环随机挑一条跑
|
||||
sql = '''
|
||||
SELECT `id`,json_data,prox FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL
|
||||
SELECT `id`,json_data,prox,city,mt_traceid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL and current_count<10;
|
||||
'''
|
||||
sql = '''
|
||||
SELECT `id`,json_data,prox FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and ((is_ok != 403 and is_ok != 418 and is_ok != 401) or is_ok is null)
|
||||
SELECT `id`,json_data,prox,city,mt_traceid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and is_ok is NULL;
|
||||
'''
|
||||
# sql = '''
|
||||
# SELECT `id`,json_data,prox,city,mt_traceid FROM `hotel_hd` WHERE title LIKE '%美团酒店详情%' and ((is_ok != 403 and is_ok != 418 and is_ok != 401) or is_ok is null) and id=12635
|
||||
# '''
|
||||
headers = tent2.get_shoppingmalls(sql)
|
||||
return headers
|
||||
|
||||
def update_headers(self, is_ok, ind):
|
||||
if is_ok == 1:
|
||||
sql = f'''
|
||||
UPDATE hotel_hd SET current_count=current_count+1,req_count=req_count+1,prox='{json.dumps(self.proxy)}' WHERE `id`={ind}
|
||||
'''
|
||||
def run_one(self, items):
|
||||
prox_cities = []
|
||||
for prox_city in self.proxy_list:
|
||||
if prox_city[1]:
|
||||
prox_cities.append(prox_city[1])
|
||||
headers_cities = []
|
||||
for headers_city in items:
|
||||
if headers_city[3]:
|
||||
headers_cities.append(headers_city[3])
|
||||
if headers_cities:
|
||||
task_city = headers_cities[random.randint(0, len(headers_cities) - 1)]
|
||||
else:
|
||||
sql = f'''
|
||||
UPDATE hotel_hd SET is_ok={is_ok},prox='{json.dumps(self.proxy)}' WHERE `id`={ind}
|
||||
'''
|
||||
tent2.update_data(sql)
|
||||
|
||||
def get_prox(self):
|
||||
sql = '''
|
||||
SELECT prox_data FROM proxs_list WHERE channel LIKE '%住宅%' ORDER BY RAND() LIMIT 1
|
||||
'''
|
||||
prox = tent2.get_shoppingmalls(sql)
|
||||
print(json.loads(prox[0][0]))
|
||||
return json.loads(prox[0][0])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
while True:
|
||||
ht = hotel_run()
|
||||
items = ht.get_headers()
|
||||
print(items)
|
||||
item = items[random.randint(0, len(items) - 1)]
|
||||
ind, hd, prox = item
|
||||
task_city = prox_cities[random.randint(0, len(prox_cities) - 1)]
|
||||
task = get_one_task(self.VENDOR, self.USER, self.PWD, task_city, task_city)
|
||||
print(task)
|
||||
if not task:
|
||||
print(task_city)
|
||||
return -1
|
||||
cityName = task['data']['cityName']
|
||||
none_city_item_list = []
|
||||
items = list(items)
|
||||
random.shuffle(items)
|
||||
item = None
|
||||
for j in items:
|
||||
if j[3] is None:
|
||||
none_city_item_list.append(j)
|
||||
elif j[3] in cityName:
|
||||
item = j
|
||||
break
|
||||
if not item:
|
||||
item = none_city_item_list[0]
|
||||
# 跑单条抓包:解析 headers -> 绑定城市/IP -> 分接口请求 -> 回写状态
|
||||
ind, hd, prox, city, mt_traceid = item
|
||||
url, headers, data = json.loads(hd)
|
||||
if '{' in data:
|
||||
if isinstance(data, str) and '{' in data:
|
||||
data = json.loads(data)
|
||||
new_url, params = parse_url(url)
|
||||
# 上次响应有 traceId 时,带回请求头继续跑
|
||||
if mt_traceid:
|
||||
headers['M-TRACEID'] = mt_traceid
|
||||
self.last_trace_id = mt_traceid
|
||||
|
||||
# city/prox 只要已有绑定就优先沿用,避免城市和 IP 来回跳
|
||||
if city and prox:
|
||||
self.proxy = json.loads(prox)
|
||||
self.bound_city = city
|
||||
elif city and not prox:
|
||||
# 有城市没IP:从代理池里补同城 IP
|
||||
matched = [p for p in self.proxy_list if p[1] == city]
|
||||
if not matched:
|
||||
print(f"城市 {city} 在代理池无IP,跳过")
|
||||
return
|
||||
self.proxy = json.loads(matched[0][0])
|
||||
self.bound_city = city
|
||||
elif not city and prox:
|
||||
# 有IP没城市:反查这个 IP 属于哪个城市
|
||||
matched = [p for p in self.proxy_list if p[0] == prox]
|
||||
if not matched:
|
||||
print(f"ID={ind} 有IP但反查不到城市,跳过")
|
||||
return
|
||||
self.bound_city = matched[0][1]
|
||||
self.proxy = json.loads(prox)
|
||||
city = self.bound_city
|
||||
else:
|
||||
# 全新包:随机拿一个 IP,并把城市绑定回 hotel_hd
|
||||
# pick = self.proxy_list[random.randint(0, len(self.proxy_list) - 1)]
|
||||
for pick in self.proxy_list:
|
||||
if pick[1] == cityName.replace('市',''):
|
||||
self.proxy = json.loads(pick[0])
|
||||
self.bound_city = pick[1]
|
||||
break
|
||||
city = self.bound_city
|
||||
|
||||
print(f"本次使用: 城市={self.bound_city}, proxy={self.proxy}")
|
||||
|
||||
try:
|
||||
# 根据抓包 URL 分发到对应请求函数
|
||||
if '/hotel/core/router/shelf' in new_url:
|
||||
result = ht.run_shelf(new_url, params, headers, data, prox)
|
||||
result = self.run_shelf(new_url, params, headers, data, None, task)
|
||||
if result == -1:
|
||||
return -1
|
||||
elif '/productapi/v3/prepayList' in new_url:
|
||||
result = ht.run_prepayList(new_url, params, headers, prox)
|
||||
ht.update_headers(result, ind)
|
||||
result = self.run_prepayList(new_url, params, headers, None, task)
|
||||
if result == -1:
|
||||
return -1
|
||||
else:
|
||||
print(f"未知接口,跳过: {new_url}")
|
||||
return
|
||||
self.update_headers(result, ind, city, self.last_trace_id)
|
||||
except Exception as e:
|
||||
# 获取详细报错信息
|
||||
error_msg = f"""
|
||||
{'=' * 50}
|
||||
时间: {time.strftime('%Y-%m-%d %H:%M:%S')}
|
||||
@@ -428,6 +604,56 @@ if __name__ == '__main__':
|
||||
is_ok = 403
|
||||
else:
|
||||
is_ok = 0
|
||||
ht.update_headers(is_ok, ind)
|
||||
time.sleep(random.randint(1, 3))
|
||||
self.update_headers(is_ok, ind, city, None)
|
||||
|
||||
def update_headers(self, is_ok, ind, city, mt_traceid):
|
||||
# 成功只累计次数,失败写 is_ok 状态,proxy/city/traceId 都回填
|
||||
if is_ok == 1:
|
||||
sql = f'''
|
||||
UPDATE hotel_hd SET current_count=current_count+1,req_count=req_count+1,prox='{json.dumps(self.proxy)}',city='{city}',mt_traceid='{mt_traceid}' WHERE `id`={ind}
|
||||
'''
|
||||
else:
|
||||
sql = f'''
|
||||
UPDATE hotel_hd SET is_ok={is_ok},prox='{json.dumps(self.proxy)}',city='{city}',mt_traceid='{mt_traceid}' WHERE `id`={ind}
|
||||
'''
|
||||
tent2.update_data(sql)
|
||||
|
||||
def _find_trace_id(self, obj):
|
||||
"""递归找响应里第一个 traceId 值"""
|
||||
if isinstance(obj, dict):
|
||||
if 'traceId' in obj:
|
||||
return str(obj['traceId'])
|
||||
for v in obj.values():
|
||||
r = self._find_trace_id(v)
|
||||
if r:
|
||||
return r
|
||||
elif isinstance(obj, list):
|
||||
for item in obj:
|
||||
r = self._find_trace_id(item)
|
||||
if r:
|
||||
return r
|
||||
return None
|
||||
|
||||
def get_city_id(self, city_name):
|
||||
"""从 area_info 查美团 cityId,查不到返回 None"""
|
||||
sql = f"SELECT cityId FROM area_crood.area_info WHERE cityName='{city_name}' and title like '%美团%' LIMIT 1"
|
||||
rows = tent.get_shoppingmalls(sql)
|
||||
if rows:
|
||||
return rows[0][0]
|
||||
return None
|
||||
|
||||
def get_prox(self):
|
||||
sql = '''
|
||||
SELECT prox_data,city FROM project_proxy.proxs_list WHERE channel ORDER BY RAND()
|
||||
'''
|
||||
prox_list = tent2.get_shoppingmalls(sql)
|
||||
return prox_list
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
for i in range(1000):
|
||||
ht = hotel_run()
|
||||
items = ht.get_headers()
|
||||
ht.run_one(items)
|
||||
time.sleep(random.randint(2, 5))
|
||||
# run2()
|
||||
|
||||
Reference in New Issue
Block a user