From a5d9b8e28a3b87dc520b53f65e7022b8e6b0f009 Mon Sep 17 00:00:00 2001 From: xingc Date: Thu, 11 Dec 2025 19:50:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(card):=20=E4=BF=AE=E5=A4=8D`psa`=E6=90=9C?= =?UTF-8?q?=E5=8D=A1=E9=AA=8C=E8=AF=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/routers/card/scraper.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/core/routers/card/scraper.py b/core/routers/card/scraper.py index 833a9ac..272b420 100644 --- a/core/routers/card/scraper.py +++ b/core/routers/card/scraper.py @@ -22,6 +22,17 @@ from core.utils.helper import async_retry, decrypt_aes_cbc, generate_keyname logger = logging.getLogger(__name__) +async def get_cf_clearance(platform: str) -> dict: + redis_conn = await get_cache() + async with redis_conn: + cache_session_str = await redis_conn.get(generate_keyname(f'session:{platform}')) + if isinstance(cache_session_str, str): + headers = ujson.decode(cache_session_str) + else: + headers = {} + return headers + + class SiteApi: def __init__(self): self.user_agent = UserAgent( @@ -99,9 +110,12 @@ class SiteApi: headers = { # 'X-Requested-With': 'XMLHttpRequest', 'Origin': 'https://www.psacard.com', - 'Referer': f'https://www.psacard.com/cert/{cert_number}', + 'Referer': f'https://www.psacard.com/cert/{cert_number}/psa', } - r = await self.get(url, headers=headers, impersonate="chrome110") + + cf_clearance_headers = await get_cf_clearance(platform='psa') + headers.update(cf_clearance_headers) + r = await self.get(url, headers=headers, use_abroad_proxy=True, use_random_ua=False, http_version=2, impersonate="chrome110") return r async def psa_images(self, cert_number: str | int, images_id: str | int): @@ -130,14 +144,7 @@ class SiteApi: async def cgc(self, cert_number: str | int): """CGC""" url = f'https://www.cgccards.com/certlookup/{cert_number}/' - redis_conn = await get_cache() - async with redis_conn: - cache_session_str = await redis_conn.get(generate_keyname('session:cgc')) - if isinstance(cache_session_str, str): - headers = ujson.decode(cache_session_str) - else: - headers = {} - + headers = await get_cf_clearance(platform='cgc') return await self.get(url, headers=headers, use_random_ua=False, use_abroad_proxy=True) async def gbtc(self, cert_number: str | int): @@ -229,7 +236,7 @@ class CardScraper: if html.xpath('//div[contains(@class, "wrapper")]//h1/text()').get() is not None: return - info_elements = html.xpath('//div[@hidden and @id]/div[contains(@class, "py-3")]') + info_elements = html.xpath('//dl[@class="text-body1"]/div[contains(@class, "py-3")]') info = dict() for info_element in info_elements: name = info_element.xpath('./dt[1]').xpath('string()').get() or info_element.xpath( @@ -267,8 +274,8 @@ class CardScraper: item['card_type'] = info.get('category') # 卡片正、反图片(远程) item['card_spare_picture'] = { - 'front_picture': html.xpath('//div[contains(@class, "flex")]//span/noscript/img[@alt="left"]/@src').get(), - 'reverse_picture': html.xpath('//div[contains(@class, "flex")]//span/noscript/img[@alt="right"]/@src').get() + 'front_picture': html.xpath('//div[contains(@class, "flex")]//span//img[@alt="left"]/@src').get(), + 'reverse_picture': html.xpath('//div[contains(@class, "flex")]//span//img[@alt="right"]/@src').get() } # 来源