demo.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # -*- coding: utf-8 -*-
  2. # Author : Charley
  3. # Python : 3.10.8
  4. # Date : 2025/9/25 11:26
  5. import requests
  6. import user_agent
  7. from parsel import Selector
  8. # headers = {
  9. # "accept": "application/json, text/plain, */*",
  10. # "referer": "https://www.jihuanshe.com/",
  11. # "user-agent": user_agent.generate_user_agent()
  12. # }
  13. # url = "https://api.jihuanshe.com/api/market/share/auction-product"
  14. # params = {
  15. # "auction_product_id": 26,
  16. # "url": f"https://www.jihuanshe.com/app/auction?auctionProductId={26}"
  17. # }
  18. # response = requests.get(url, headers=headers, params=params, timeout=5)
  19. # print(response.json())
  20. # print(response)
  21. # print(response.url)
  22. HEADERS = {
  23. "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
  24. "user-agent": user_agent.generate_user_agent()
  25. }
  26. COOKIES = {
  27. "CaptchaValue": "eyJhbGdvcml0aG0iOiJTSEEtMjU2IiwiY2hhbGxlbmdlIjoiNTZlNTBmMzU4MWRlMGYyNGQ5OGI2MTBhYTJlMTdmNjIzNzU4MDdmZjExOWM2MjNjYTRhNzUyY2MxMmU3ZDNmYyIsIm51bWJlciI6NDUxMTcsInNhbHQiOiJmNWU0ODBkZWNhMDNmYmJmNzdiN2UyYmYiLCJzaWduYXR1cmUiOiI3ZjlkMTc3NjllOTMwM2I3NTM5OTRlNzRlZDg0MzU3NTZkMzljMzU5YTFhMzBmODAzODNlMWI4YjA0MGZhZDVjIiwidG9vayI6ODJ9",
  28. "saved-language": "zh-CN",
  29. "SessionID": "dd60b7e4-f638-41cd-bb56-e2e4929aee27",
  30. "_ga": "GA1.1.706688626.1757584379",
  31. "AltchaSessionID": "1622a445-bf77-43e5-be67-13b76ff8e5ca",
  32. "_ga_55FF3CQQK2": "GS2.1.s1758539017$o6$g0$t1758539017$j60$l0$h0"
  33. }
  34. url = f"https://cards.cgccards.cn/certlookup/6060110001/"
  35. resp =requests.get(url, headers=HEADERS, cookies=COOKIES)
  36. print(resp.text)
  37. print(resp.status_code)
  38. selector = Selector(resp.text)
  39. tag_dl_list = selector.xpath('//div[@class="results-pane"]/div[@class="certlookup-intro"]//dl')
  40. # 初始化变量
  41. data_dict = {
  42. "rating_number": None,
  43. "year": None,
  44. "manufacturer": None,
  45. "card_set": None,
  46. "card_no": None,
  47. "player": None,
  48. # "belonging": None,
  49. "grade": None,
  50. "image_front": None,
  51. "image_back": None
  52. }
  53. # 提取详细信息
  54. for tag_dl in tag_dl_list:
  55. dt_text = tag_dl.xpath('./dt/text()').get()
  56. dd_text = tag_dl.xpath('./dd/text()').get()
  57. if dt_text == "评级号码":
  58. data_dict["rating_number"] = dd_text.strip() if dd_text else None
  59. elif dt_text == "年份":
  60. data_dict["year"] = dd_text
  61. elif dt_text == "制造商":
  62. data_dict["manufacturer"] = dd_text
  63. elif dt_text == "套装":
  64. data_dict["card_set"] = dd_text
  65. elif dt_text == "卡牌编号":
  66. data_dict["card_no"] = dd_text
  67. elif dt_text == "球员":
  68. data_dict["player"] = dd_text
  69. # elif dt_text == "归属":
  70. # data_dict["belonging"] = dd_text
  71. elif dt_text == "评级等级":
  72. data_dict["grade"] = dd_text.strip() if dd_text else None
  73. # 提取图片链接
  74. tag_img_list = selector.xpath('//div[@class="results-pane"]//div[@class="certlookup-images-item"]/a/@href').getall()
  75. if len(tag_img_list) >= 2:
  76. data_dict["image_front"] = tag_img_list[0]
  77. data_dict["image_back"] = tag_img_list[1]
  78. elif len(tag_img_list) == 1:
  79. data_dict["image_front"] = tag_img_list[0]
  80. print(data_dict)