如何设置Airbnb Api“扩展”范围?

发布于 2025-01-29 21:50:40 字数 1855 浏览 3 评论 0原文

我试图通过普通的HTTP请求来刮擦Airbnb ,并注意到了一些东西。

假设我们使用此搜索字符串:“纽约,纽约,美国”。

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

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密钥几乎​​是公开的,所以不关心。

“变量”参数的可读内容是:

{
  "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
}

“扩展”参数的可读内容是:

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

我试图找出哈希的来源。

看来它是从GraphQl查询中计算出来的,但我什么都不知道,也没有关于它的文档。

有帮助吗?

I am trying to scrape AirBNB by plain HTTP requests and noticed something.

Let's say we use this search string: "New York, New York, United States".

The simplest working request (striped off from unnecessary headers and fields) I can use to get the desired results is this:

GET /api/v3/ExploreSections?operationName=ExploreSections&locale=en¤cy=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

At this point, that API key is pretty much public, so not a concern.

The readable content of the "variables" parameter is this:

{
  "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
}

The readable content of the "extensions" parameter is this:

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

I am trying to figure out where that hash comes from.

It seems it's calculated from a GraphQL query but I don't know anything else and there is no documentation about it.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉栀 2025-02-05 21:50:40

我遇到了同样的问题(想获得价格),然后在har文件中调查了您可以使用Chrome获得的har文件后,我发现您从称为pdpplatformroute.xxx.js的JavaScript文件中获得此

值只是为了加载文件pdpplatformroute.xxx.js,然后解析文件以获取“ protiveID”。

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

// 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];
}

I had the same issue (wanted to get the prices) and after investigating in the HAR files that you can get with Chrome, I found out that you get this value from a Javascript file called PdpPlatformRoute.xxx.js

The steps to get this hash are simply to load the file PdpPlatformRoute.xxx.js, then to parse the file to get an "operationId".

If this helps, this is how I did this.

// 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];
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文