|
|
@@ -37,7 +37,7 @@ class YsbSpider:
|
|
|
self.db_online = MySQLPoolOnline()
|
|
|
|
|
|
def get_token(self, _retry_login=False):
|
|
|
- sql_account = f""" select `name`,`cookie_str` from `accounts_platform` where `platform`=5 and `status`=1 and `equipment_id`=3 order by `cookie_timestamp` asc limit 1 """
|
|
|
+ sql_account = f""" select `name`,`cookie_str` from `accounts_platform` where `platform`=5 and `status`=1 and `equipment_id`=1 order by `cookie_timestamp` asc limit 1 """
|
|
|
account_list = self.db_online.select_data(sql_account)
|
|
|
if not account_list:
|
|
|
logger.error("无可用爬取账号")
|
|
|
@@ -133,7 +133,7 @@ class YsbSpider:
|
|
|
}
|
|
|
|
|
|
def build_base_payload(self):
|
|
|
- keyword = ""
|
|
|
+ keyword = self.product
|
|
|
if self.brand:
|
|
|
keyword = self.brand + " " + self.product
|
|
|
if self.product_desc:
|
|
|
@@ -342,7 +342,6 @@ class YsbSpider:
|
|
|
response = None
|
|
|
time.sleep(10)
|
|
|
if not response or response.status_code != 200:
|
|
|
- self.is_success = False
|
|
|
logger.error("第%s页请求失败,停止爬取", page)
|
|
|
return
|
|
|
|
|
|
@@ -350,7 +349,6 @@ class YsbSpider:
|
|
|
data_json = response.json()
|
|
|
except json.JSONDecodeError:
|
|
|
logger.exception("第%s页响应不是合法 JSON", page)
|
|
|
- self.is_success = False
|
|
|
return
|
|
|
data_block = data_json.get("data") or {}
|
|
|
if data_json.get("message", "") == "该操作需要登录":
|
|
|
@@ -359,7 +357,6 @@ class YsbSpider:
|
|
|
time.sleep(10)
|
|
|
if not self.get_token():
|
|
|
logger.error("登录后仍未从库中读到有效 Token,停止重试")
|
|
|
- self.is_success = False
|
|
|
return
|
|
|
logger.info("token 已刷新,重试第 %s 页", page)
|
|
|
continue
|
|
|
@@ -373,8 +370,7 @@ class YsbSpider:
|
|
|
json_data = self.decrypt_payload(encrypted_o)
|
|
|
except Exception as e:
|
|
|
logger.exception("第%s页解密失败: %s", page, e)
|
|
|
- self.is_success = False
|
|
|
- return
|
|
|
+ continue
|
|
|
wholesales = json_data.get("wholesales", [])
|
|
|
if not wholesales:
|
|
|
logger.info(f"第{page}页无数据,停止")
|
|
|
@@ -408,8 +404,6 @@ class YsbSpider:
|
|
|
try:
|
|
|
self.search_data()
|
|
|
except Exception as e:
|
|
|
-
|
|
|
- self.is_success = False
|
|
|
logger.error(e)
|
|
|
|
|
|
logger.info(f"爬取总数{self.pipeline.crawl_count}")
|