json 如何使用Requests传递带有数据的查询字符串

enxuqcxy  于 2023-04-08  发布在  其他
关注(0)|答案(1)|浏览(96)

我试图使用POST请求方法通过传递一个查询与我的数据。
这是curl命令:

curl "https://www.vrbo.com/serp/g" -X POST -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0" -H "Accept: */*" -H "Accept-Language: en-GB,en;q=0.5" -H "Accept-Encoding: gzip, deflate, br" -H "Referer: https://www.vrbo.com/en-ca/search/keywords:montreal-quebec-canada/^@45.5251350310451,-73.76729659947267,45.69613218421512,-73.06485824498048,11z/minNightlyPrice/0?filterByTotalPrice=true&petIncluded=false&ssr=true" -H "content-type: application/json" -H "x-csrf-token: iPvaAUs1HROGljo24r9LIurTHPyPmWEYlRnVTkqgrg3" -H "x-homeaway-site: homeaway_ca" -H "x-ha-location: city=MONTREAL, region=QC, country=CA, lat=45.50, lng=-73.58, asn=147049" -H "apollographql-client-name: web_serp" -H "ha-serp-force-graphql-err: undefined" -H "Origin: https://www.vrbo.com" -H "Connection: keep-alive" -H "Cookie: cesc=^%^7B^%^22marketingClick^%^22^%^3A^%^5B^%^22false^%^22^%^2C1680613984103^%^5D^%^2C^%^22hitNumber^%^22^%^3A^%^5B^%^223^%^22^%^2C1680613984103^%^5D^%^2C^%^22visitNumber^%^22^%^3A^%^5B^%^226^%^22^%^2C1680613920806^%^5D^%^2C^%^22entryPage^%^22^%^3A^%^5B^%^22DtX6E0m6yE0dqr0pVLgIz2HnjXDx1aXGMcq1v1iejIg^%^3D^%^22^%^2C1680613984103^%^5D^%^7D; MC1=GUID=1dd95f7adb420e35fe1d9f06311e91c3; DUAID=1dd95f7a-db42-0e35-fe1d-9f06311e91c3; ha-device-id=1dd95f7a-db42-0e35-fe1d-9f06311e91c3; hav=1dd95f7a-db42-0e35-fe1d-9f06311e91c3; _gcl_aw=GCL.1676406243.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; _gcl_dc=GCL.1676406243.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; _gcl_au=1.1.70134909.1676406242; _ha_aw=GCL.1676406242.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; _ha_dc=GCL.1676406242.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; _ha2_aw=GCL.1676406242.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; _ha2_dc=GCL.1676406242.CjwKCAiA_6yfBhBNEiwAkmXy5xGkLYVjINBt23NUm_RfKXVgFSgXtArto07KpP1XVi5D_ox_QECuBhoCunAQAvD_BwE; cto_bundle=7ngBRF9UNlNNS25lRmRSa2klMkJYQ2VQTUM2VTdVTm14bjBYOXVPb0pLV2JlVURDR1lGM0pUVUo4WDZVQjJYQ1habktnb3FTbUR2U2pQVk9CNUdQazZLdURHQVhjJTJGU0oxZU9DWXVZR21mQ3BVQmQ3UCUyQk1vamhZYVN6RyUyQmk4YU9FMUlqejFv; xdid=f07ebeb5-87e1-449c-b2a3-65b19c9f1b8b^|1676406244^|vrbo.com; edge-polyfill-location=city^%^3DMONTREAL^%^2C^%^20region^%^3DQC^%^2C^%^20country^%^3DCA^%^2C^%^20lat^%^3D45.50^%^2C^%^20lng^%^3D-73.58^%^2C^%^20asn^%^3D147049^%^2C^%^20city^%^3DMONTREAL^%^2C^%^20region^%^3DQC^%^2C^%^20country^%^3DCA^%^2C^%^20lat^%^3D45.50^%^2C^%^20lng^%^3D-73.58^%^2C^%^20asn^%^3D147049; edge-polyfill-device-classification=10; _ga=GA1.2.221959039.1677684145; tracker_device=56215dc5-9fe6-4813-9ca5-a3e34cc98413; has=57b92a25-e45f-3847-973b-fd1b065689b3; 57b92a25-e45f-3847-973b-fd1b065689b3UAL=1; 57b92a25-e45f-3847-973b-fd1b065689b3SL=1; DUAID=1dd95f7a-db42-0e35-fe1d-9f06311e91c3; ln_or=eyIxMjI2OTUzIjoiZCJ9; eg_ppid=1a3a6039-4e85-48e0-9710-a73c8c336a91; crumb=iPvaAUs1HROGljo24r9LIurTHPyPmWEYlRnVTkqgrg3; site=homeaway_ca; ha-trip-prst=^%^7B^%^22petIncluded^%^22^%^3Afalse^%^7D; ha-state-prst=^%^7B^%^22lbsKeywords^%^22^%^3A^%^22Montreal^%^2C^%^20Quebec^%^2C^%^20Canada^%^22^%^2C^%^22lastSearchUrl^%^22^%^3A^%^22^%^2Fsearch^%^2Fkeywords^%^3Amontreal-quebec-canada^%^2F^%^4045.5251350310451^%^2C-73.76729659947267^%^2C45.69613218421512^%^2C-73.06485824498048^%^2C11z^%^2FminNightlyPrice^%^2F0^%^3FpetIncluded^%^3Dfalse^%^26filterByTotalPrice^%^3Dtrue^%^26ssr^%^3Dtrue^%^22^%^7D; ensighten:source={""source"":null,""medium"":null,""lastAffiliate"":null,""sessionid"":""57b92a25-e45f-3847-973b-fd1b065689b3""}; _gid=GA1.2.1691859150.1680552023; HMS=1effb36e-70f4-4b97-b1d8-9643b74966b3; eu-site=0; ak_bmsc=0F0FA9CAAD94A1BFC77D080D6102683E~000000000000000000000000000000~YAAQJgQ1FyqtzSuHAQAACQhlTBNR1PRNmqRZID4f9jt+q2m/BpQmnD7vCvAO0y5XDl+BnoALTr6JoAISRw67+9pHVxiXpIfOFabNTm2M5C/gs0fg6py7YMlRI4w9Wo4u2Mo6/VX1Kk/aEahZIMNQNi7YFHjoPORb92WbHfy11hKLcPP0/yQRnYBq20/9hI8bXcwGhe+2sUGEMi5l5v+q6bR6UFehCH73RMGBsWXvREHrJZ9A8g97/eLJok89CySGqVik8U10DRXquFcJRHEVbrm7rwpoNwlngBqzXOSNqum3BZ2g2vY6/fwAO9YvNCsA/J45wXPj7quwhoyGaplBJyEkTV0fRwqCtNjBjxKlokURAyVGTvGpJAi2fxbSaeLwjG1GL5nKhAI=; bm_sv=0C7F881CECA6EFF9859FE04ED638A89C~YAAQJgQ1F5iyzSuHAQAA4klmTBPpEL+BcwKuEyiYGoB9dlPQ31QWgvyb/KNciuYrDooPfa8h4etgJGToyUWLWWc0C3xULKziho9dyME1B6sKy6teS3O1CDASv91nd0ZdnPIsEbhNGiPDO/OcNnQ3Eu/lH9JpQ8U2Md4oYrV+F1eJq40PlthgFqLUuvYkVNQX+ktz9a7QHJ2rAhsNKAgJvaRKq8d0m+l4/upHxRJWBYKCzhsNHW0BgGEfOwSxsS0=~1; _dd_s=rum=2&id=c6da2c6e-ff24-49cf-99f4-1a81f603e7cd&created=1680613922360&expire=1680614882370; ta_timeout=1; _uetsid=6eeb9760d25811ed924d69e1bc651929; _uetvid=851b59f0aca511edbc4f73c5057866b2" -H "Sec-Fetch-Dest: empty" -H "Sec-Fetch-Mode: cors" -H "Sec-Fetch-Site: same-origin" -H "TE: trailers" --data-raw "{""operationName"":""SearchRequestQuery"",""variables"":{""filterCounts"":true,""request"":{""paging"":{""page"":1,""pageSize"":50},""filterVersion"":""1"",""filters"":^[^],""coreFilters"":{""maxBathrooms"":null,""maxBedrooms"":null,""maxNightlyPrice"":null,""maxTotalPrice"":null,""minBathrooms"":0,""minBedrooms"":0,""minNightlyPrice"":0,""minTotalPrice"":null,""pets"":0},""boundingBox"":{""maxLat"":45.69613218421512,""maxLng"":-73.06485824498048,""minLat"":45.5251350310451,""minLng"":-73.76729659947267},""q"":""montreal-quebec-canada""},""optimizedBreadcrumb"":false,""vrbo_web_global_messaging_banner"":true},""extensions"":{""isPageLoadSearch"":true},""query"":""query SearchRequestQuery(\$request: SearchResultRequest^!, \$filterCounts: Boolean^!, \$optimizedBreadcrumb: Boolean^!, \$vrbo_web_global_messaging_banner: Boolean^!) {\\n  results: search(request: \$request) {\\n    ...querySelectionSet\\n    ...DestinationBreadcrumbsSearchResult\\n    ...DestinationMessageSearchResult\\n    ...FilterCountsSearchRequestResult\\n    ...HitCollectionSearchResult\\n    ...ADLSearchResult\\n    ...MapSearchResult\\n    ...ExpandedGroupsSearchResult\\n    ...PagerSearchResult\\n    ...InternalToolsSearchResult\\n    ...SEOMetaDataParamsSearchResult\\n    ...GlobalInlineMessageSearchResult\\n    ...GlobalBannerContainerSearchResult ^@include(if: \$vrbo_web_global_messaging_banner)\\n    __typename\\n  }\\n}\\n\\nfragment querySelectionSet on SearchResult {\\n  id\\n  typeaheadSuggestion {\\n    uuid\\n    term\\n    name\\n    __typename\\n  }\\n  geography {\\n    lbsId\\n    gaiaId\\n    location {\\n      latitude\\n      longitude\\n      __typename\\n    }\\n    isGeocoded\\n    shouldShowMapCentralPin\\n    __typename\\n  }\\n  propertyRedirectUrl\\n  __typename\\n}\\n\\nfragment DestinationBreadcrumbsSearchResult on SearchResult {\\n  destination(optimizedBreadcrumb: \$optimizedBreadcrumb) {\\n    breadcrumbs {\\n      name\\n      url\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment HitCollectionSearchResult on SearchResult {\\n  page\\n  pageSize\\n  pageCount\\n  queryUUID\\n  percentBooked {\\n    currentPercentBooked\\n    __typename\\n  }\\n  listings {\\n    ...HitListing\\n    __typename\\n  }\\n  resultCount\\n  pinnedListing {\\n    headline\\n    listing {\\n      ...HitListing\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment HitListing on Listing {\\n  virtualTourBadge {\\n    name\\n    id\\n    helpText\\n    __typename\\n  }\\n  amenitiesBadges {\\n    name\\n    id\\n    helpText\\n    __typename\\n  }\\n  images {\\n    altText\\n    c6_uri\\n    c9_uri\\n    mab {\\n      banditId\\n      payloadId\\n      campaignId\\n      cached\\n      arm {\\n        level\\n        imageUrl\\n        categoryName\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  ...HitInfoListing\\n  __typename\\n}\\n\\nfragment HitInfoListing on Listing {\\n  listingId\\n  ...HitInfoDesktopListing\\n  ...HitInfoMobileListing\\n  ...PriceListing\\n  __typename\\n}\\n\\nfragment HitInfoDesktopListing on Listing {\\n  detailPageUrl\\n  instantBookable\\n  minStayRange {\\n    minStayHigh\\n    minStayLow\\n    __typename\\n  }\\n  listingId\\n  listingNumber\\n  rankedBadges(rankingStrategy: SERP) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  propertyId\\n  propertyMetadata {\\n    headline\\n    __typename\\n  }\\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  unitMetadata {\\n    unitName\\n    __typename\\n  }\\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  ...DetailsListing\\n  ...GeoDistanceListing\\n  ...PriceListing\\n  ...RatingListing\\n  __typename\\n}\\n\\nfragment DetailsListing on Listing {\\n  bathrooms {\\n    full\\n    half\\n    toiletOnly\\n    __typename\\n  }\\n  bedrooms\\n  propertyType\\n  sleeps\\n  petsAllowed\\n  spaces {\\n    spacesSummary {\\n      area {\\n        areaValue\\n        __typename\\n      }\\n      bedCountDisplay\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GeoDistanceListing on Listing {\\n  geoDistance {\\n    text\\n    relationType\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PriceListing on Listing {\\n  priceSummary: priceSummary {\\n    priceAccurate\\n    ...PriceSummaryTravelerPriceSummary\\n    __typename\\n  }\\n  priceSummarySecondary: priceSummary(summary: \\""displayPriceSecondary\\"") {\\n    ...PriceSummaryTravelerPriceSummary\\n    __typename\\n  }\\n  priceLabel: priceSummary(summary: \\""priceLabel\\"") {\\n    priceTypeId\\n    pricePeriodDescription\\n    __typename\\n  }\\n  prices {\\n    ...VrboTravelerPriceSummary\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PriceSummaryTravelerPriceSummary on TravelerPriceSummary {\\n  priceTypeId\\n  edapEventJson\\n  formattedAmount\\n  roundedFormattedAmount\\n  pricePeriodDescription\\n  __typename\\n}\\n\\nfragment VrboTravelerPriceSummary on PriceSummary {\\n  perNight {\\n    amount\\n    formattedAmount\\n    roundedFormattedAmount\\n    pricePeriodDescription\\n    __typename\\n  }\\n  total {\\n    amount\\n    formattedAmount\\n    roundedFormattedAmount\\n    pricePeriodDescription\\n    __typename\\n  }\\n  label\\n  mainPrice\\n  __typename\\n}\\n\\nfragment RatingListing on Listing {\\n  averageRating\\n  reviewCount\\n  __typename\\n}\\n\\nfragment HitInfoMobileListing on Listing {\\n  detailPageUrl\\n  instantBookable\\n  minStayRange {\\n    minStayHigh\\n    minStayLow\\n    __typename\\n  }\\n  listingId\\n  listingNumber\\n  rankedBadges(rankingStrategy: SERP) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  propertyId\\n  propertyMetadata {\\n    headline\\n    __typename\\n  }\\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  unitMetadata {\\n    unitName\\n    __typename\\n  }\\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  ...DetailsListing\\n  ...GeoDistanceListing\\n  ...PriceListing\\n  ...RatingListing\\n  __typename\\n}\\n\\nfragment ExpandedGroupsSearchResult on SearchResult {\\n  expandedGroups {\\n    ...ExpandedGroupExpandedGroup\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment ExpandedGroupExpandedGroup on ExpandedGroup {\\n  listings {\\n    ...HitListing\\n    ...MapHitListing\\n    __typename\\n  }\\n  mapViewport {\\n    neLat\\n    neLong\\n    swLat\\n    swLong\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment MapHitListing on Listing {\\n  ...HitListing\\n  geoCode {\\n    latitude\\n    longitude\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment FilterCountsSearchRequestResult on SearchResult {\\n  id\\n  resultCount\\n  filterGroups {\\n    groupInfo {\\n      name\\n      id\\n      __typename\\n    }\\n    filters {\\n      count ^@include(if: \$filterCounts)\\n      checked\\n      filter {\\n        id\\n        name\\n        refineByQueryArgument\\n        description\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment MapSearchResult on SearchResult {\\n  mapViewport {\\n    neLat\\n    neLong\\n    swLat\\n    swLong\\n    __typename\\n  }\\n  page\\n  pageSize\\n  listings {\\n    ...MapHitListing\\n    __typename\\n  }\\n  pinnedListing {\\n    listing {\\n      ...MapHitListing\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PagerSearchResult on SearchResult {\\n  fromRecord\\n  toRecord\\n  pageSize\\n  pageCount\\n  page\\n  resultCount\\n  __typename\\n}\\n\\nfragment DestinationMessageSearchResult on SearchResult {\\n  destinationMessage(assetVersion: 4) {\\n    iconTitleText {\\n      title\\n      message\\n      icon\\n      messageValueType\\n      link {\\n        linkText\\n        linkHref\\n        __typename\\n      }\\n      __typename\\n    }\\n    ...DestinationMessageDestinationMessage\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment DestinationMessageDestinationMessage on DestinationMessage {\\n  iconText {\\n    message\\n    icon\\n    messageValueType\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment ADLSearchResult on SearchResult {\\n  parsedParams {\\n    q\\n    coreFilters {\\n      adults\\n      children\\n      pets\\n      minBedrooms\\n      maxBedrooms\\n      minBathrooms\\n      maxBathrooms\\n      minNightlyPrice\\n      maxNightlyPrice\\n      minSleeps\\n      __typename\\n    }\\n    dates {\\n      arrivalDate\\n      departureDate\\n      __typename\\n    }\\n    sort\\n    __typename\\n  }\\n  page\\n  pageSize\\n  pageCount\\n  resultCount\\n  fromRecord\\n  toRecord\\n  pinnedListing {\\n    listing {\\n      listingId\\n      __typename\\n    }\\n    __typename\\n  }\\n  listings {\\n    listingId\\n    __typename\\n  }\\n  filterGroups {\\n    filters {\\n      checked\\n      filter {\\n        groupId\\n        id\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  geography {\\n    lbsId\\n    name\\n    description\\n    location {\\n      latitude\\n      longitude\\n      __typename\\n    }\\n    primaryGeoType\\n    breadcrumbs {\\n      name\\n      countryCode\\n      location {\\n        latitude\\n        longitude\\n        __typename\\n      }\\n      primaryGeoType\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment InternalToolsSearchResult on SearchResult {\\n  internalTools {\\n    searchServiceUrl\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment SEOMetaDataParamsSearchResult on SearchResult {\\n  page\\n  resultCount\\n  pageSize\\n  geography {\\n    name\\n    lbsId\\n    breadcrumbs {\\n      name\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalInlineMessageSearchResult on SearchResult {\\n  globalMessages {\\n    ...GlobalInlineAlertGlobalMessages\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalInlineAlertGlobalMessages on GlobalMessages {\\n  alert {\\n    action {\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    body {\\n      text {\\n        value\\n        __typename\\n      }\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    id\\n    severity\\n    title {\\n      value\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalBannerContainerSearchResult on SearchResult {\\n  globalMessages {\\n    ...GlobalBannerGlobalMessages\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalBannerGlobalMessages on GlobalMessages {\\n  banner {\\n    body {\\n      text {\\n        value\\n        __typename\\n      }\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    id\\n    severity\\n    title {\\n      value\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n""}"

在发送curl命令中找到的数据字符串时,我得到以下错误消息:

{'statusCode': 400, 'error': 'Bad Request', 'message': 'Invalid request payload JSON format'}

对数据部分做了一些修改,我尝试只发送第一部分而不发送查询,如下所示:

'{"operationName":"SearchRequestQuery",\
"variables":{"filterCounts":"true",\
"request":{"paging":{"page":"1","pageSize":"50"},\
"filterVersion":"1","filters":"^[^]",\
"coreFilters":{"maxBathrooms":"null","maxBedrooms":"null","maxNightlyPrice":"null","maxTotalPrice":"null","minBathrooms":"0","minBedrooms":"0","minNightlyPrice":"0","minTotalPrice":"null","pets":"0"},\
"boundingBox":{"maxLat":"45.69613218421512","maxLng":"-73.06485824498048","minLat":"45.5251350310451","minLng":"-73.76729659947267"},\
"q":"montreal-quebec-canada"},\
"optimizedBreadcrumb":"false","vrbo_web_global_messaging_banner":"true"},\
"extensions":{"isPageLoadSearch":"true"}}'

这让我得到了以下回应:

{'statusCode': 400, 'error': 'Bad Request', 'message': 'Must provide query string.'}

然后,我尝试在数据包后复制粘贴查询部分,但得到了Invalid request payload JSON format错误消息。

data = '{"operationName":"SearchRequestQuery",\
       "variables":{"filterCounts":"true",\
        "request":{"paging":{"page":"1","pageSize":"50"},\
        "filterVersion":"1","filters":"^[^]",\
        "coreFilters":{"maxBathrooms":"null","maxBedrooms":"null","maxNightlyPrice":"null","maxTotalPrice":"null","minBathrooms":"0","minBedrooms":"0","minNightlyPrice":"0","minTotalPrice":"null","pets":"0"},\
        "boundingBox":{"maxLat":"45.69613218421512","maxLng":"-73.06485824498048","minLat":"45.5251350310451","minLng":"-73.76729659947267"},\
        "q":"montreal-quebec-canada"},\
        "optimizedBreadcrumb":"false","vrbo_web_global_messaging_banner":"true"},\
        "extensions":{"isPageLoadSearch":"true"}}, 
query:query SearchRequestQuery($request: SearchResultRequest^!, $filterCounts: Boolean^!, $optimizedBreadcrumb: Boolean^!, $vrbo_web_global_messaging_banner: Boolean^!) {\\n  results: search(request: $request) {\\n    ...querySelectionSet\\n    ...DestinationBreadcrumbsSearchResult\\n    ...DestinationMessageSearchResult\\n    ...FilterCountsSearchRequestResult\\n    ...HitCollectionSearchResult\\n    ...ADLSearchResult\\n    ...MapSearchResult\\n    ...ExpandedGroupsSearchResult\\n    ...PagerSearchResult\\n    ...InternalToolsSearchResult\\n    ...SEOMetaDataParamsSearchResult\\n    ...GlobalInlineMessageSearchResult\\n    ...GlobalBannerContainerSearchResult ^@include(if: $vrbo_web_global_messaging_banner)\\n    __typename\\n  }\\n}\\n\\nfragment querySelectionSet on SearchResult {\\n  id\\n  typeaheadSuggestion {\\n    uuid\\n    term\\n    name\\n    __typename\\n  }\\n  geography {\\n    lbsId\\n    gaiaId\\n    location {\\n      latitude\\n      longitude\\n      __typename\\n    }\\n    isGeocoded\\n    shouldShowMapCentralPin\\n    __typename\\n  }\\n  propertyRedirectUrl\\n  __typename\\n}\\n\\nfragment DestinationBreadcrumbsSearchResult on SearchResult {\\n  destination(optimizedBreadcrumb: $optimizedBreadcrumb) {\\n    breadcrumbs {\\n      name\\n      url\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment HitCollectionSearchResult on SearchResult {\\n  page\\n  pageSize\\n  pageCount\\n  queryUUID\\n  percentBooked {\\n    currentPercentBooked\\n    __typename\\n  }\\n  listings {\\n    ...HitListing\\n    __typename\\n  }\\n  resultCount\\n  pinnedListing {\\n    headline\\n    listing {\\n      ...HitListing\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment HitListing on Listing {\\n  virtualTourBadge {\\n    name\\n    id\\n    helpText\\n    __typename\\n  }\\n  amenitiesBadges {\\n    name\\n    id\\n    helpText\\n    __typename\\n  }\\n  images {\\n    altText\\n    c6_uri\\n    c9_uri\\n    mab {\\n      banditId\\n      payloadId\\n      campaignId\\n      cached\\n      arm {\\n        level\\n        imageUrl\\n        categoryName\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  ...HitInfoListing\\n  __typename\\n}\\n\\nfragment HitInfoListing on Listing {\\n  listingId\\n  ...HitInfoDesktopListing\\n  ...HitInfoMobileListing\\n  ...PriceListing\\n  __typename\\n}\\n\\nfragment HitInfoDesktopListing on Listing {\\n  detailPageUrl\\n  instantBookable\\n  minStayRange {\\n    minStayHigh\\n    minStayLow\\n    __typename\\n  }\\n  listingId\\n  listingNumber\\n  rankedBadges(rankingStrategy: SERP) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  propertyId\\n  propertyMetadata {\\n    headline\\n    __typename\\n  }\\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  unitMetadata {\\n    unitName\\n    __typename\\n  }\\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  ...DetailsListing\\n  ...GeoDistanceListing\\n  ...PriceListing\\n  ...RatingListing\\n  __typename\\n}\\n\\nfragment DetailsListing on Listing {\\n  bathrooms {\\n    full\\n    half\\n    toiletOnly\\n    __typename\\n  }\\n  bedrooms\\n  propertyType\\n  sleeps\\n  petsAllowed\\n  spaces {\\n    spacesSummary {\\n      area {\\n        areaValue\\n        __typename\\n      }\\n      bedCountDisplay\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GeoDistanceListing on Listing {\\n  geoDistance {\\n    text\\n    relationType\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PriceListing on Listing {\\n  priceSummary: priceSummary {\\n    priceAccurate\\n    ...PriceSummaryTravelerPriceSummary\\n    __typename\\n  }\\n  priceSummarySecondary: priceSummary(summary: \\displayPriceSecondary\\) {\\n    ...PriceSummaryTravelerPriceSummary\\n    __typename\\n  }\\n  priceLabel: priceSummary(summary: \\priceLabel\\) {\\n    priceTypeId\\n    pricePeriodDescription\\n    __typename\\n  }\\n  prices {\\n    ...VrboTravelerPriceSummary\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PriceSummaryTravelerPriceSummary on TravelerPriceSummary {\\n  priceTypeId\\n  edapEventJson\\n  formattedAmount\\n  roundedFormattedAmount\\n  pricePeriodDescription\\n  __typename\\n}\\n\\nfragment VrboTravelerPriceSummary on PriceSummary {\\n  perNight {\\n    amount\\n    formattedAmount\\n    roundedFormattedAmount\\n    pricePeriodDescription\\n    __typename\\n  }\\n  total {\\n    amount\\n    formattedAmount\\n    roundedFormattedAmount\\n    pricePeriodDescription\\n    __typename\\n  }\\n  label\\n  mainPrice\\n  __typename\\n}\\n\\nfragment RatingListing on Listing {\\n  averageRating\\n  reviewCount\\n  __typename\\n}\\n\\nfragment HitInfoMobileListing on Listing {\\n  detailPageUrl\\n  instantBookable\\n  minStayRange {\\n    minStayHigh\\n    minStayLow\\n    __typename\\n  }\\n  listingId\\n  listingNumber\\n  rankedBadges(rankingStrategy: SERP) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  propertyId\\n  propertyMetadata {\\n    headline\\n    __typename\\n  }\\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  unitMetadata {\\n    unitName\\n    __typename\\n  }\\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\\n    id\\n    helpText\\n    name\\n    __typename\\n  }\\n  ...DetailsListing\\n  ...GeoDistanceListing\\n  ...PriceListing\\n  ...RatingListing\\n  __typename\\n}\\n\\nfragment ExpandedGroupsSearchResult on SearchResult {\\n  expandedGroups {\\n    ...ExpandedGroupExpandedGroup\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment ExpandedGroupExpandedGroup on ExpandedGroup {\\n  listings {\\n    ...HitListing\\n    ...MapHitListing\\n    __typename\\n  }\\n  mapViewport {\\n    neLat\\n    neLong\\n    swLat\\n    swLong\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment MapHitListing on Listing {\\n  ...HitListing\\n  geoCode {\\n    latitude\\n    longitude\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment FilterCountsSearchRequestResult on SearchResult {\\n  id\\n  resultCount\\n  filterGroups {\\n    groupInfo {\\n      name\\n      id\\n      __typename\\n    }\\n    filters {\\n      count ^@include(if: $filterCounts)\\n      checked\\n      filter {\\n        id\\n        name\\n        refineByQueryArgument\\n        description\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment MapSearchResult on SearchResult {\\n  mapViewport {\\n    neLat\\n    neLong\\n    swLat\\n    swLong\\n    __typename\\n  }\\n  page\\n  pageSize\\n  listings {\\n    ...MapHitListing\\n    __typename\\n  }\\n  pinnedListing {\\n    listing {\\n      ...MapHitListing\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment PagerSearchResult on SearchResult {\\n  fromRecord\\n  toRecord\\n  pageSize\\n  pageCount\\n  page\\n  resultCount\\n  __typename\\n}\\n\\nfragment DestinationMessageSearchResult on SearchResult {\\n  destinationMessage(assetVersion: 4) {\\n    iconTitleText {\\n      title\\n      message\\n      icon\\n      messageValueType\\n      link {\\n        linkText\\n        linkHref\\n        __typename\\n      }\\n      __typename\\n    }\\n    ...DestinationMessageDestinationMessage\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment DestinationMessageDestinationMessage on DestinationMessage {\\n  iconText {\\n    message\\n    icon\\n    messageValueType\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment ADLSearchResult on SearchResult {\\n  parsedParams {\\n    q\\n    coreFilters {\\n      adults\\n      children\\n      pets\\n      minBedrooms\\n      maxBedrooms\\n      minBathrooms\\n      maxBathrooms\\n      minNightlyPrice\\n      maxNightlyPrice\\n      minSleeps\\n      __typename\\n    }\\n    dates {\\n      arrivalDate\\n      departureDate\\n      __typename\\n    }\\n    sort\\n    __typename\\n  }\\n  page\\n  pageSize\\n  pageCount\\n  resultCount\\n  fromRecord\\n  toRecord\\n  pinnedListing {\\n    listing {\\n      listingId\\n      __typename\\n    }\\n    __typename\\n  }\\n  listings {\\n    listingId\\n    __typename\\n  }\\n  filterGroups {\\n    filters {\\n      checked\\n      filter {\\n        groupId\\n        id\\n        __typename\\n      }\\n      __typename\\n    }\\n    __typename\\n  }\\n  geography {\\n    lbsId\\n    name\\n    description\\n    location {\\n      latitude\\n      longitude\\n      __typename\\n    }\\n    primaryGeoType\\n    breadcrumbs {\\n      name\\n      countryCode\\n      location {\\n        latitude\\n        longitude\\n        __typename\\n      }\\n      primaryGeoType\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment InternalToolsSearchResult on SearchResult {\\n  internalTools {\\n    searchServiceUrl\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment SEOMetaDataParamsSearchResult on SearchResult {\\n  page\\n  resultCount\\n  pageSize\\n  geography {\\n    name\\n    lbsId\\n    breadcrumbs {\\n      name\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalInlineMessageSearchResult on SearchResult {\\n  globalMessages {\\n    ...GlobalInlineAlertGlobalMessages\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalInlineAlertGlobalMessages on GlobalMessages {\\n  alert {\\n    action {\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    body {\\n      text {\\n        value\\n        __typename\\n      }\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    id\\n    severity\\n    title {\\n      value\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalBannerContainerSearchResult on SearchResult {\\n  globalMessages {\\n    ...GlobalBannerGlobalMessages\\n    __typename\\n  }\\n  __typename\\n}\\n\\nfragment GlobalBannerGlobalMessages on GlobalMessages {\\n  banner {\\n    body {\\n      text {\\n        value\\n        __typename\\n      }\\n      link {\\n        href\\n        text {\\n          value\\n          __typename\\n        }\\n        __typename\\n      }\\n      __typename\\n    }\\n    id\\n    severity\\n    title {\\n      value\\n      __typename\\n    }\\n    __typename\\n  }\\n  __typename\\n}\\n}'

我试图删除\\n和/或\n,但仍然得到相同的错误信息。
如何将上一个查询包含到我的数据包中?

vq8itlhq

vq8itlhq1#

这是curl请求的--raw-data中的GraphQL查询,因此它会导致字符串转义的一些困难。远程服务器无法解析传入的查询并给你错误消息。
我对你的查询做了什么(从query SearchRequestQuery($req...开始的--raw-data的一部分:

  • 删除^符号
  • //""替换为"
  • \\n替换为\n
  • --raw-data的其余部分转换为python表示(dict)

因此,在python + requests中,您的问题的正确请求将如下所示:

import requests

JSON_DATA = {
    "operationName": "SearchRequestQuery",
    "variables": {
        "filterCounts": True,
        "request": {
            "paging": {
                "page": 1,
                "pageSize": 50
            },
            "filterVersion": "1",
            "filters": "^[^]",
            "coreFilters": {
                "maxBathrooms": None,
                "maxBedrooms": None,
                "maxNightlyPrice": None,
                "maxTotalPrice": None,
                "minBathrooms": 0,
                "minBedrooms": 0,
                "minNightlyPrice": 0,
                "minTotalPrice": None,
                "pets": 0
            },
            "boundingBox": {
                "maxLat": 45.69613218421512,
                "maxLng": -73.06485824498048,
                "minLat": 45.5251350310451,
                "minLng": -73.76729659947267
            },
            "q": "montreal-quebec-canada"
        },
        "optimizedBreadcrumb": False,
        "vrbo_web_global_messaging_banner": True
    },
    "extensions": {"isPageLoadSearch": True},
    "query": 'query SearchRequestQuery($request: SearchResultRequest!, $filterCounts: Boolean!, $optimizedBreadcrumb: Boolean!, $vrbo_web_global_messaging_banner: Boolean!) {\n  results: search(request: $request) {\n    ...querySelectionSet\n    ...DestinationBreadcrumbsSearchResult\n    ...DestinationMessageSearchResult\n    ...FilterCountsSearchRequestResult\n    ...HitCollectionSearchResult\n    ...ADLSearchResult\n    ...MapSearchResult\n    ...ExpandedGroupsSearchResult\n    ...PagerSearchResult\n    ...InternalToolsSearchResult\n    ...SEOMetaDataParamsSearchResult\n    ...GlobalInlineMessageSearchResult\n    ...GlobalBannerContainerSearchResult @include(if: $vrbo_web_global_messaging_banner)\n    __typename\n  }\n}\n\nfragment querySelectionSet on SearchResult {\n  id\n  typeaheadSuggestion {\n    uuid\n    term\n    name\n    __typename\n  }\n  geography {\n    lbsId\n    gaiaId\n    location {\n      latitude\n      longitude\n      __typename\n    }\n    isGeocoded\n    shouldShowMapCentralPin\n    __typename\n  }\n  propertyRedirectUrl\n  __typename\n}\n\nfragment DestinationBreadcrumbsSearchResult on SearchResult {\n  destination(optimizedBreadcrumb: $optimizedBreadcrumb) {\n    breadcrumbs {\n      name\n      url\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment HitCollectionSearchResult on SearchResult {\n  page\n  pageSize\n  pageCount\n  queryUUID\n  percentBooked {\n    currentPercentBooked\n    __typename\n  }\n  listings {\n    ...HitListing\n    __typename\n  }\n  resultCount\n  pinnedListing {\n    headline\n    listing {\n      ...HitListing\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment HitListing on Listing {\n  virtualTourBadge {\n    name\n    id\n    helpText\n    __typename\n  }\n  amenitiesBadges {\n    name\n    id\n    helpText\n    __typename\n  }\n  images {\n    altText\n    c6_uri\n    c9_uri\n    mab {\n      banditId\n      payloadId\n      campaignId\n      cached\n      arm {\n        level\n        imageUrl\n        categoryName\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n  ...HitInfoListing\n  __typename\n}\n\nfragment HitInfoListing on Listing {\n  listingId\n  ...HitInfoDesktopListing\n  ...HitInfoMobileListing\n  ...PriceListing\n  __typename\n}\n\nfragment HitInfoDesktopListing on Listing {\n  detailPageUrl\n  instantBookable\n  minStayRange {\n    minStayHigh\n    minStayLow\n    __typename\n  }\n  listingId\n  listingNumber\n  rankedBadges(rankingStrategy: SERP) {\n    id\n    helpText\n    name\n    __typename\n  }\n  propertyId\n  propertyMetadata {\n    headline\n    __typename\n  }\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\n    id\n    helpText\n    name\n    __typename\n  }\n  unitMetadata {\n    unitName\n    __typename\n  }\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\n    id\n    helpText\n    name\n    __typename\n  }\n  ...DetailsListing\n  ...GeoDistanceListing\n  ...PriceListing\n  ...RatingListing\n  __typename\n}\n\nfragment DetailsListing on Listing {\n  bathrooms {\n    full\n    half\n    toiletOnly\n    __typename\n  }\n  bedrooms\n  propertyType\n  sleeps\n  petsAllowed\n  spaces {\n    spacesSummary {\n      area {\n        areaValue\n        __typename\n      }\n      bedCountDisplay\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment GeoDistanceListing on Listing {\n  geoDistance {\n    text\n    relationType\n    __typename\n  }\n  __typename\n}\n\nfragment PriceListing on Listing {\n  priceSummary: priceSummary {\n    priceAccurate\n    ...PriceSummaryTravelerPriceSummary\n    __typename\n  }\n  priceSummarySecondary: priceSummary(summary: "displayPriceSecondary") {\n    ...PriceSummaryTravelerPriceSummary\n    __typename\n  }\n  priceLabel: priceSummary(summary: "priceLabel") {\n    priceTypeId\n    pricePeriodDescription\n    __typename\n  }\n  prices {\n    ...VrboTravelerPriceSummary\n    __typename\n  }\n  __typename\n}\n\nfragment PriceSummaryTravelerPriceSummary on TravelerPriceSummary {\n  priceTypeId\n  edapEventJson\n  formattedAmount\n  roundedFormattedAmount\n  pricePeriodDescription\n  __typename\n}\n\nfragment VrboTravelerPriceSummary on PriceSummary {\n  perNight {\n    amount\n    formattedAmount\n    roundedFormattedAmount\n    pricePeriodDescription\n    __typename\n  }\n  total {\n    amount\n    formattedAmount\n    roundedFormattedAmount\n    pricePeriodDescription\n    __typename\n  }\n  label\n  mainPrice\n  __typename\n}\n\nfragment RatingListing on Listing {\n  averageRating\n  reviewCount\n  __typename\n}\n\nfragment HitInfoMobileListing on Listing {\n  detailPageUrl\n  instantBookable\n  minStayRange {\n    minStayHigh\n    minStayLow\n    __typename\n  }\n  listingId\n  listingNumber\n  rankedBadges(rankingStrategy: SERP) {\n    id\n    helpText\n    name\n    __typename\n  }\n  propertyId\n  propertyMetadata {\n    headline\n    __typename\n  }\n  superlativesBadges: rankedBadges(rankingStrategy: SERP_SUPERLATIVES) {\n    id\n    helpText\n    name\n    __typename\n  }\n  unitMetadata {\n    unitName\n    __typename\n  }\n  webRatingBadges: rankedBadges(rankingStrategy: SRP_WEB_RATING) {\n    id\n    helpText\n    name\n    __typename\n  }\n  ...DetailsListing\n  ...GeoDistanceListing\n  ...PriceListing\n  ...RatingListing\n  __typename\n}\n\nfragment ExpandedGroupsSearchResult on SearchResult {\n  expandedGroups {\n    ...ExpandedGroupExpandedGroup\n    __typename\n  }\n  __typename\n}\n\nfragment ExpandedGroupExpandedGroup on ExpandedGroup {\n  listings {\n    ...HitListing\n    ...MapHitListing\n    __typename\n  }\n  mapViewport {\n    neLat\n    neLong\n    swLat\n    swLong\n    __typename\n  }\n  __typename\n}\n\nfragment MapHitListing on Listing {\n  ...HitListing\n  geoCode {\n    latitude\n    longitude\n    __typename\n  }\n  __typename\n}\n\nfragment FilterCountsSearchRequestResult on SearchResult {\n  id\n  resultCount\n  filterGroups {\n    groupInfo {\n      name\n      id\n      __typename\n    }\n    filters {\n      count @include(if: $filterCounts)\n      checked\n      filter {\n        id\n        name\n        refineByQueryArgument\n        description\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment MapSearchResult on SearchResult {\n  mapViewport {\n    neLat\n    neLong\n    swLat\n    swLong\n    __typename\n  }\n  page\n  pageSize\n  listings {\n    ...MapHitListing\n    __typename\n  }\n  pinnedListing {\n    listing {\n      ...MapHitListing\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment PagerSearchResult on SearchResult {\n  fromRecord\n  toRecord\n  pageSize\n  pageCount\n  page\n  resultCount\n  __typename\n}\n\nfragment DestinationMessageSearchResult on SearchResult {\n  destinationMessage(assetVersion: 4) {\n    iconTitleText {\n      title\n      message\n      icon\n      messageValueType\n      link {\n        linkText\n        linkHref\n        __typename\n      }\n      __typename\n    }\n    ...DestinationMessageDestinationMessage\n    __typename\n  }\n  __typename\n}\n\nfragment DestinationMessageDestinationMessage on DestinationMessage {\n  iconText {\n    message\n    icon\n    messageValueType\n    __typename\n  }\n  __typename\n}\n\nfragment ADLSearchResult on SearchResult {\n  parsedParams {\n    q\n    coreFilters {\n      adults\n      children\n      pets\n      minBedrooms\n      maxBedrooms\n      minBathrooms\n      maxBathrooms\n      minNightlyPrice\n      maxNightlyPrice\n      minSleeps\n      __typename\n    }\n    dates {\n      arrivalDate\n      departureDate\n      __typename\n    }\n    sort\n    __typename\n  }\n  page\n  pageSize\n  pageCount\n  resultCount\n  fromRecord\n  toRecord\n  pinnedListing {\n    listing {\n      listingId\n      __typename\n    }\n    __typename\n  }\n  listings {\n    listingId\n    __typename\n  }\n  filterGroups {\n    filters {\n      checked\n      filter {\n        groupId\n        id\n        __typename\n      }\n      __typename\n    }\n    __typename\n  }\n  geography {\n    lbsId\n    name\n    description\n    location {\n      latitude\n      longitude\n      __typename\n    }\n    primaryGeoType\n    breadcrumbs {\n      name\n      countryCode\n      location {\n        latitude\n        longitude\n        __typename\n      }\n      primaryGeoType\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment InternalToolsSearchResult on SearchResult {\n  internalTools {\n    searchServiceUrl\n    __typename\n  }\n  __typename\n}\n\nfragment SEOMetaDataParamsSearchResult on SearchResult {\n  page\n  resultCount\n  pageSize\n  geography {\n    name\n    lbsId\n    breadcrumbs {\n      name\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment GlobalInlineMessageSearchResult on SearchResult {\n  globalMessages {\n    ...GlobalInlineAlertGlobalMessages\n    __typename\n  }\n  __typename\n}\n\nfragment GlobalInlineAlertGlobalMessages on GlobalMessages {\n  alert {\n    action {\n      link {\n        href\n        text {\n          value\n          __typename\n        }\n        __typename\n      }\n      __typename\n    }\n    body {\n      text {\n        value\n        __typename\n      }\n      link {\n        href\n        text {\n          value\n          __typename\n        }\n        __typename\n      }\n      __typename\n    }\n    id\n    severity\n    title {\n      value\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n\nfragment GlobalBannerContainerSearchResult on SearchResult {\n  globalMessages {\n    ...GlobalBannerGlobalMessages\n    __typename\n  }\n  __typename\n}\n\nfragment GlobalBannerGlobalMessages on GlobalMessages {\n  banner {\n    body {\n      text {\n        value\n        __typename\n      }\n      link {\n        href\n        text {\n          value\n          __typename\n        }\n        __typename\n      }\n      __typename\n    }\n    id\n    severity\n    title {\n      value\n      __typename\n    }\n    __typename\n  }\n  __typename\n}\n',
}

HEADERS = {
    "Accept-Encoding": "gzip, deflate, br",
    "x-ha-location": "city=MONTREAL, region=QC, country=CA, lat=45.50, "
                     "lng=-73.58, asn=147049",
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                  'AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/111.0.0.0 Safari/537.36',
}

def get_serp_data():
    with requests.Session() as sess:
        sess.get("https://www.vrbo.com")  # obtain session and cookies
        r = sess.post(
            "https://www.vrbo.com/serp/g",
            headers=HEADERS,
            json=JSON_DATA,
        )
        print(r.status_code)  # 200
        print(r.json())  # actual response data, no errors

if __name__ == '__main__':
    get_serp_data()

相关问题