我正在尝试使用隐藏的airbnb api。我需要反向工程ID来自于GET请求的查询字符串。例如,以下面的清单为例:
https://www.airbnb.ca/rooms/47452643
“公共”ID显示为47452643。但是,使用API需要另一个ID。
如果您查看Chrome中的XHR请求,您将看到一个以“StaysPdpSections?operationName”开头的请求。这就是我想复制的请求。如果我将请求复制为“失眠”或“邮递员”,则会在查询字符串中看到一个变量,其开头为:
"variables":"{"id":"U3RheUxpc3Rpbmc6NDc0NTI2NDM=“
隐藏的ID "U3RheUxpc3Rpbmc6NDc0NTI2NDM“是我需要的。它需要从这个请求中获取数据,并且必须插入查询字符串。如何动态恢复每个清单的隐藏ID "U3RheUxpc3Rpbmc6NDc0NTI2NDM“?
发布于 2022-02-13 00:20:49
目标id被埋在html中很深.
import requests
from bs4 import BeautifulSoup as bs
import json
url = 'https://www.airbnb.ca/rooms/47452643'
req = requests.get(url)
soup = bs(req.content, 'html.parser')
script = soup.select_one('script[type="application/json"][id="data-state"]')
data = json.loads(script.text)
target = data.get('niobeMinimalClientData')[2][1]['variables']
print(target.get('id'))输出:
U3RheUxpc3Rpbmc6NDc0NTI2NDM=https://stackoverflow.com/questions/71094965
复制相似问题