精神残废
2021-11-02 02:58
采纳率: 60%
浏览 62
已结题

爬虫爬取香港迪士尼网上商品也详情,报错400,并且有一个请求参数错误,不太懂

网站地址:

代码

import requests
from fake_useragent import UserAgent
class HKSpider:
    def __init__(self):
        self.url='https://www.hongkongdisneyland.com/zh-cn/tickets-api/promotion/ws'
        self.headers={
            "Accept": "application/json, text/plain, */*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Content-Length": "245",
            "Content-Type": "application/json",
            'Cookie': 'geolocation_aka_hkdl_jar=%7B%22zipCode%22%3A%22%22%2C%22region%22%3A%22SC%22%2C%22country%22%3A%22CN%22%2C%22metro%22%3A%22CHENGDU%22%2C%22metroCode%22%3A%22%22%7D; localeCookie_jar_aka=%7B%22contentLocale%22%3A%22zh_CN%22%2C%22version%22%3A%223%22%2C%22precedence%22%3A0%2C%22akamai%22%3A%22true%22%7D; languageSelection_jar_aka=%7B%22preferredLanguage%22%3A%22zh-cn%22%2C%22version%22%3A%221%22%2C%22precedence%22%3A0%2C%22language%22%3A%22zh-cn%22%2C%22akamai%22%3A%22true%22%7D; check=true; AMCVS_EDA101AC512D2B230A490D4C%40AdobeOrg=1; sn.vi=f451c27d-8331-42e6-b36d-f2078aa7f3f0; _gcl_au=1.1.1284066220.1635778392; sn.tpc=1; _ga=GA1.2.1122472326.1635778415; _gid=GA1.2.333436093.1635778415; PHPSESSID=bjio4c3e8optse1mspf4bvkh86; localeCookie_jar=%7B%22contentLocale%22%3A%22zh_CN%22%2C%22version%22%3A%223%22%2C%22precedence%22%3A0%7D; GEOLOCATION_jar=%7B%22zipCode%22%3A100000%2C%22region%22%3A%22beijing+shi%22%2C%22country%22%3A%22china%22%2C%22metro%22%3A%22beijing%22%2C%22metroCode%22%3A%22156001%22%2C%22countryisocode%22%3A%22CHN%22%7D; LANGUAGE_MESSAGE_DISPLAY=1; languageSelection_jar=%7B%22language%22%3A%22zh-cn%22%2C%22precedence%22%3A0%7D; at_check=true; WDPROView=%7B%22version%22%3A2%2C%22preferred%22%3A%7B%22device%22%3A%22desktop%22%2C%22screenWidth%22%3A1280%2C%22screenHeight%22%3A1024%7D%2C%22deviceInfo%22%3A%7B%22device%22%3A%22desktop%22%2C%22screenWidth%22%3A1280%2C%22screenHeight%22%3A1024%7D%2C%22browserInfo%22%3A%7B%22agent%22%3A%22Chrome%22%2C%22version%22%3A%2294.0.4606.81%22%7D%7D; LPVID=E4ZTYxNDAzNGRmNjljZDc1; mboxEdgeCluster=32; AMCV_EDA101AC512D2B230A490D4C%40AdobeOrg=-330454231%7CMCIDTS%7C18933%7CMCMID%7C21883592571191269821529873215392913503%7CMCAAMLH-1636392801%7C11%7CMCAAMB-1636392801%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1635795201s%7CNONE%7CMCAID%7CNONE%7CvVersion%7C3.1.2; LPSID-65526753=o0Yb5Tj0R_GaQwLTRox6Hw; bm_mi=378444BE2FA4BE4D6BED49FF05BEB385~B86UDUJYEJLPhLHjZ5KZUcyQAVCtE3sXbsZu/j03PNBjgix5oa48fe4RFfaC4gLUoL4M7XGpUxiEwZ1GYjwtP33CoL9lk3dI6+8tP3/PicBwoDfSDExAVN7r8dMp65gnqX6dcInpXGGSIY5CZ/u7eYhC3hpE6Dh0Fm1QfIOzPc4nrjgAiB/WneNDeJLZHqpRfXWawsYDOLVlRkTyTvQIlgI6+dEONozL5+tNJdTsLQD9ADbzJ0uq4NTtmkDAC9neZ1dc3qRIaDjNYJ9ekISXZBzhWUOk/gySAVYMmgGr9kpYwUP2SANgmost8J4+D65xxX64WdhEgZrtQFlDaM5oJE7UBbfjE6jipnBihaYEys4=; ak_bmsc=46496AB26860A3FE69CB72D9BDF10283~000000000000000000000000000000~YAAQxQ8kF6VjJ9p8AQAASFWQ3A0vgEuvOhrUxOcZXPBy2ilKFVXBhGIiYjJ6LGyZwuqF4u5SkGeGjQAQZiO48yu05SiWqHKXvaGIwNJRxiP6jqONcxJ1pQiG3tCwehQx2jmHrePmVyy6PiHqcdqLt80aquMEmV+KppfdsYJnvLohIqCRCTG11Lrxsa7t0XARS1nGw0hFU6Ojxf2VQsGcVTsotV+MnIIkz5sicRCcvQK7oE6osfwiSXOnqY11SxYmPzghwRCpDh1a+ldC3DBAo1jZiDFKt6Q6SnYaz7IN2eOUmYo+WJe1w6CqSfxQspjOp2V0oe7JdcoZcP+vnsu2PeWFNcxvh3mBjFIhJtzliKqDZ3DZbK5JR7rMr8sWPoqNSd9HFQyQ/3xnjrtaKUx4TUdnOpWfr4HcywXUy5uXDKVcjfOe6JdWPQFuLJ2VMEKOxYBKjboTY3QnAomLHObFZstZ4bljPQ3HeaUjIVwVM13VpMFtEO0=; s_pers=%20s_gpv_pn%3Dwdpro%252Fhkdl%252Fintl%252Fzh-cn%252Fcommerce%252Ftickets%252Fconsumer%252Fselect%252Fdining%7C1635789921361%3B; s_sess=%20s_sq%3D%3B%20s_tp%3D2082%3B%20s_ppv%3Dwdpro%252Fhkdl%252Fintl%252Fzh-cn%252Fcommerce%252Ftickets%252Fconsumer%252Fselect%252Fdining%252C32%252C32%252C657%3B%20s_slt%3D%3B%20s_cc%3Dtrue%3B; mbox=PC#f916a8bc1a1c425f90310b28b6650ffa.32_0#1699032923|session#4d8dc57b6ae34ff39f3abfe3bba00281#1635789861; dl_promo=%7B%22entryUrl%22%3A%22merchandise%22%2C%22ipAddress%22%3A%22240e%3A474%3A2d05%3A4431%3A69b4%3A276%3Ace59%3A877c%22%2C%22mappingCode%22%3A%22751d7c77-b0a5-4a25-b7b6-b4688376d6ac%22%7D; akavpau_HKDL_waiting_room_zh-cn_book=1635788526~id=cd67b10f034f2c29e9f734e9de0e9a0d; ADRUM_BTa="R:89|g:f5228985-7bad-4eb3-bf20-533c235798b8"; ADRUM_BT1="R:89|i:307433|e:133"; bm_sv=25DFDE6325902FC181E4AE19F9305AE0~W+Jtz2gSjr56ns+n5PiWo7pYdX2rOb0nLK4eiDoCdfQh50pu3rY+9IeI3DAccgE5FwYFL0JJqVa7hKhHuzzu7g6PmGRyyhKBZgCLN4OfMxh4mZJEyg/v+FjeD6PtSS9jFdnjXF+cFV4L6+GaCG0Q897cMLMPwauo7br5sWdXsUY=',

            "Host": "www.hongkongdisneyland.com",
            "Origin": "https://www.hongkongdisneyland.com",
            "Pragma": "no-cache",
            "Referer": "https://www.hongkongdisneyland.com/zh-cn/book/promotion/merchandise/online-merchandise-gm",
            "sec-ch-ua-mobile": "?0",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-origin",
            "User-Agent": UserAgent().random,
        }
        self.data={
            'method': "getPage",
            'nameId': '',
            'parameters': [
                {
                    'parameter': {'pk': "c96af76f-5c7f-4006-bb6d-171ce7940eb7", 'uri': "online-merchandise-gm"},
                    'type': '',
                 }
            ],
           'payloadId': "bd7f6e5a-354f-44ac-c8ca-ee6de5e5a933",
            'serviceName': "storefront.ThemeParkTicket",
        }
    #发起请求
    def __request(self):
        res=requests.post(url=self.url,headers=self.headers,data=self.data)
        #检查是否成功
        print(res.status_code)
        print(res.text)
    def run(self):
        self.__request()
if __name__=='__main__':
    spider=HKSpider()
    spider.run()

img

img

img

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 江天暮雪丨 2021-11-02 10:06
    最佳回答

    参数 data 改为 json 试试:
    requests.post(...., json=self.data)

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题