fix(card): 修复psa搜卡验证问题
This commit is contained in:
@@ -22,6 +22,17 @@ from core.utils.helper import async_retry, decrypt_aes_cbc, generate_keyname
|
|||||||
logger = logging.getLogger(__name__)
|
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:
|
class SiteApi:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.user_agent = UserAgent(
|
self.user_agent = UserAgent(
|
||||||
@@ -99,9 +110,12 @@ class SiteApi:
|
|||||||
headers = {
|
headers = {
|
||||||
# 'X-Requested-With': 'XMLHttpRequest',
|
# 'X-Requested-With': 'XMLHttpRequest',
|
||||||
'Origin': 'https://www.psacard.com',
|
'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
|
return r
|
||||||
|
|
||||||
async def psa_images(self, cert_number: str | int, images_id: str | int):
|
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):
|
async def cgc(self, cert_number: str | int):
|
||||||
"""CGC"""
|
"""CGC"""
|
||||||
url = f'https://www.cgccards.com/certlookup/{cert_number}/'
|
url = f'https://www.cgccards.com/certlookup/{cert_number}/'
|
||||||
redis_conn = await get_cache()
|
headers = await get_cf_clearance(platform='cgc')
|
||||||
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 = {}
|
|
||||||
|
|
||||||
return await self.get(url, headers=headers, use_random_ua=False, use_abroad_proxy=True)
|
return await self.get(url, headers=headers, use_random_ua=False, use_abroad_proxy=True)
|
||||||
|
|
||||||
async def gbtc(self, cert_number: str | int):
|
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:
|
if html.xpath('//div[contains(@class, "wrapper")]//h1/text()').get() is not None:
|
||||||
return
|
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()
|
info = dict()
|
||||||
for info_element in info_elements:
|
for info_element in info_elements:
|
||||||
name = info_element.xpath('./dt[1]').xpath('string()').get() or info_element.xpath(
|
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_type'] = info.get('category')
|
||||||
# 卡片正、反图片(远程)
|
# 卡片正、反图片(远程)
|
||||||
item['card_spare_picture'] = {
|
item['card_spare_picture'] = {
|
||||||
'front_picture': html.xpath('//div[contains(@class, "flex")]//span/noscript/img[@alt="left"]/@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/noscript/img[@alt="right"]/@src').get()
|
'reverse_picture': html.xpath('//div[contains(@class, "flex")]//span//img[@alt="right"]/@src').get()
|
||||||
}
|
}
|
||||||
|
|
||||||
# 来源
|
# 来源
|
||||||
|
|||||||
Reference in New Issue
Block a user