【问题标题】:How to set the AirBNB API "extensions" parameter?如何设置 AirBNB API“扩展”参数?
【发布时间】:2022-09-26 06:52:35
【问题描述】:

我正在尝试刮 AirBNB通过普通的 HTTP 请求并注意到了一些东西。

假设我们使用这个搜索字符串:\"纽约,纽约,美国\"。

我可以用来获得所需结果的最简单的工作请求(从不必要的标题和字段中删除)是:

GET /api/v3/ExploreSections?operationName=ExploreSections&locale=en&currency=USD&variables=%7B%22isInitialLoad%22%3Atrue%2C%22hasLoggedIn%22%3Afalse%2C%22cdnCacheSafe%22%3Afalse%2C%22source%22%3A%22EXPLORE%22%2C%22exploreRequest%22%3A%7B%22metadataOnly%22%3Afalse%2C%22version%22%3A%221.8.3%22%2C%22itemsPerGrid%22%3A20%2C%22placeId%22%3A%22ChIJOwg_06VPwokRYv534QaPC8g%22%2C%22query%22%3A%22New%20York%2C%20New%20York%2C%20United%20States%22%2C%22cdnCacheSafe%22%3Afalse%2C%22screenSize%22%3A%22large%22%2C%22isInitialLoad%22%3Atrue%2C%22hasLoggedIn%22%3Afalse%7D%2C%22removeDuplicatedParams%22%3Atrue%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%2282cc0732fe2a6993a26859942d1342b6e42830704b1005aeb2d25f78732275e7%22%7D%7D HTTP/2
Host: www.airbnb.com
X-Airbnb-Api-Key: d306zoyjsyarp7ifhu67rjxn52tv0t20
Accept-Encoding: gzip, deflate

此时,该 API 密钥几乎是公开的,因此不必担心。

\"variables\" 参数的可读内容是这样的:

{
  \"isInitialLoad\": true,
  \"hasLoggedIn\": false,
  \"cdnCacheSafe\": false,
  \"source\": \"EXPLORE\",
  \"exploreRequest\": {
    \"metadataOnly\": false,
    \"version\": \"1.8.3\",
    \"itemsPerGrid\": 20,
    \"placeId\": \"ChIJOwg_06VPwokRYv534QaPC8g\",
    \"query\": \"New York, New York, United States\",
    \"cdnCacheSafe\": false,
    \"screenSize\": \"large\",
    \"isInitialLoad\": true,
    \"hasLoggedIn\": false
  },
  \"removeDuplicatedParams\": true
}

\"extensions\" 参数的可读内容是这样的:

{
  \"persistedQuery\": {
    \"version\": 1,
    \"sha256Hash\": \"82cc0732fe2a6993a26859942d1342b6e42830704b1005aeb2d25f78732275e7\"
  }
}

我试图弄清楚那个哈希是从哪里来的。

它似乎是从 GraphQL 查询中计算出来的,但我不知道其他任何东西,也没有关于它的文档。

有什么帮助吗?

    标签: web-scraping graphql airbnb-js-styleguide


    【解决方案1】:

    我遇到了同样的问题(想了解价格),在调查了您可以使用 Chrome 获得的 HAR 文件后,我发现您从一个名为 PdpPlatformRoute.xxx.js 的 Javascript 文件中获得了这个值

    获取此哈希的步骤很简单,只需加载文件 PdpPlatformRoute.xxx.js,然后解析该文件以获取“操作 ID”。

    如果这有帮助,我就是这样做的。

    // contentPage is the HTML content of the listing page (e.g. https://www.airbnb.com/rooms/1234567)
    function getPdpPlatformRouteUrl(contentPage) {
      return 'https://a0.muscache.com/airbnb/static/packages/web/en/frontend/gp-stays-pdp-route/routes/' + `${contentPage}`.match(/(PdpPlatformRoute\.\w+\.\js)/)?.[1];
    }
    
    // textContent is the JS content that you get when you fetch the previously found URL
    function getSha256(textContent) {
      return `${textContent}`.match(/name:'StaysPdpSections',type:'query',operationId:'(.*)'/)?.[1];
    }
    
    

    【讨论】:

      猜你喜欢
      • 2012-08-08
      • 1970-01-01
      • 2022-01-02
      • 2016-10-31
      • 1970-01-01
      • 2021-12-12
      • 2015-07-31
      • 2021-12-02
      • 1970-01-01
      相关资源
      最近更新 更多