pyairbnb 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyairbnb/__init__.py +7 -0
- pyairbnb/api.py +35 -0
- pyairbnb/calendarinfo.py +47 -0
- pyairbnb/details.py +29 -0
- pyairbnb/experience.py +92 -0
- pyairbnb/host.py +64 -0
- pyairbnb/host_details.py +56 -0
- pyairbnb/parse.py +34 -0
- pyairbnb/price.py +103 -0
- pyairbnb/reviews.py +66 -0
- pyairbnb/search.py +164 -0
- pyairbnb/standardize.py +233 -0
- pyairbnb/start.py +185 -0
- pyairbnb/utils.py +43 -0
- pyairbnb-0.0.3.dist-info/LICENSE +21 -0
- pyairbnb-0.0.3.dist-info/METADATA +219 -0
- pyairbnb-0.0.3.dist-info/RECORD +19 -0
- pyairbnb-0.0.3.dist-info/WHEEL +5 -0
- pyairbnb-0.0.3.dist-info/top_level.txt +1 -0
pyairbnb/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from pyairbnb.utils import parse_proxy,get_nested_value
|
|
2
|
+
from pyairbnb.api import get as get_api_key
|
|
3
|
+
from pyairbnb.host import get_listings_from_user
|
|
4
|
+
from pyairbnb.experience import search_by_place_id as experience_search_by_place_id
|
|
5
|
+
from pyairbnb.search import get_markets,get_places_ids
|
|
6
|
+
from pyairbnb.start import get_calendar,search_all,search_first_page,get_reviews,get_details
|
|
7
|
+
from pyairbnb.start import search_experience_by_taking_the_first_inputs_i_dont_care as experience_search
|
pyairbnb/api.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
ep = "https://www.airbnb.com"
|
|
5
|
+
|
|
6
|
+
regx_api_key = re.compile(r'"api_config":{"key":".+?"')
|
|
7
|
+
|
|
8
|
+
def get(proxy_url: str) -> str:
|
|
9
|
+
headers = {
|
|
10
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
11
|
+
"Accept-Language": "en",
|
|
12
|
+
"Cache-Control": "no-cache",
|
|
13
|
+
"Pragma": "no-cache",
|
|
14
|
+
"Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
15
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
16
|
+
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
17
|
+
"Sec-Fetch-Dest": "document",
|
|
18
|
+
"Sec-Fetch-Mode": "navigate",
|
|
19
|
+
"Sec-Fetch-Site": "none",
|
|
20
|
+
"Sec-Fetch-User": "?1",
|
|
21
|
+
"Upgrade-Insecure-Requests": "1",
|
|
22
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
23
|
+
}
|
|
24
|
+
proxies = {}
|
|
25
|
+
if proxy_url:
|
|
26
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
27
|
+
|
|
28
|
+
response = requests.get(ep, headers=headers, proxies=proxies, timeout=60)
|
|
29
|
+
response.raise_for_status()
|
|
30
|
+
|
|
31
|
+
body = response.text
|
|
32
|
+
api_key = regx_api_key.search(body).group()
|
|
33
|
+
api_key = api_key.replace('"api_config":{"key":"', '')
|
|
34
|
+
api_key = api_key.replace('"', "")
|
|
35
|
+
return api_key
|
pyairbnb/calendarinfo.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
import pyairbnb.utils as utils
|
|
3
|
+
from urllib.parse import urlencode
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
ep = "https://www.airbnb.com/api/v3/PdpAvailabilityCalendar/8f08e03c7bd16fcad3c92a3592c19a8b559a0d0855a84028d1163d4733ed9ade/"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get(room_id: str,month: int, year: int, api_key: str,proxy_url: str) -> str:
|
|
10
|
+
headers = {
|
|
11
|
+
"Accept": "application/json",
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
14
|
+
"X-Airbnb-Api-Key": api_key,
|
|
15
|
+
}
|
|
16
|
+
variablesData={
|
|
17
|
+
"request":{
|
|
18
|
+
"count":12,
|
|
19
|
+
"listingId":room_id,
|
|
20
|
+
"month":month,
|
|
21
|
+
"year":year,
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
entension={
|
|
25
|
+
"persistedQuery": {
|
|
26
|
+
"version":1,
|
|
27
|
+
"sha256Hash": "8f08e03c7bd16fcad3c92a3592c19a8b559a0d0855a84028d1163d4733ed9ade",
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
dataRawExtension = json.dumps(entension)
|
|
31
|
+
dataRawVariables = json.dumps(variablesData)
|
|
32
|
+
query = {
|
|
33
|
+
"operationName": "PdpAvailabilityCalendar",
|
|
34
|
+
"locale": "en",
|
|
35
|
+
"currency": "USD",
|
|
36
|
+
"variables": dataRawVariables,
|
|
37
|
+
"extensions": dataRawExtension,
|
|
38
|
+
}
|
|
39
|
+
url = f"{ep}?{urlencode(query)}"
|
|
40
|
+
proxies = {}
|
|
41
|
+
if proxy_url:
|
|
42
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
43
|
+
response = requests.get(url, headers=headers, proxies=proxies, timeout=60)
|
|
44
|
+
response.raise_for_status()
|
|
45
|
+
data = response.json()
|
|
46
|
+
calendar = utils.get_nested_value(data,"data.merlin.pdpAvailabilityCalendar.calendarMonths",[])
|
|
47
|
+
return calendar
|
pyairbnb/details.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
import pyairbnb.parse as parse
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get(room_url: str, proxy_url: str):
|
|
7
|
+
headers = {
|
|
8
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
9
|
+
"Accept-Language": "en",
|
|
10
|
+
"Cache-Control": "no-cache",
|
|
11
|
+
"Pragma": "no-cache",
|
|
12
|
+
"Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
13
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
14
|
+
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
15
|
+
"Sec-Fetch-Dest": "document",
|
|
16
|
+
"Sec-Fetch-Mode": "navigate",
|
|
17
|
+
"Sec-Fetch-Site": "none",
|
|
18
|
+
"Sec-Fetch-User": "?1",
|
|
19
|
+
"Upgrade-Insecure-Requests": "1",
|
|
20
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
21
|
+
}
|
|
22
|
+
proxies = {}
|
|
23
|
+
if proxy_url:
|
|
24
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
25
|
+
response = requests.get(room_url, headers=headers, proxies=proxies)
|
|
26
|
+
response.raise_for_status()
|
|
27
|
+
data_formatted, price_dependency_input=parse.parse_body_details_wrapper(response.text)
|
|
28
|
+
cookies = response.cookies
|
|
29
|
+
return data_formatted, price_dependency_input, cookies
|
pyairbnb/experience.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
import pyairbnb.utils as utils
|
|
4
|
+
import pyairbnb.search as search
|
|
5
|
+
import uuid
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
ep_search = "https://www.airbnb.com/api/v3/ExperiencesSearch/fbbf9989cdf264a11fce48073008bb557f7f6b43961ccda5df6a8d988bd6ef36"
|
|
9
|
+
headers = {
|
|
10
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
11
|
+
"Accept-Language": "en",
|
|
12
|
+
"Cache-Control": "no-cache",
|
|
13
|
+
"content-type": "application/json",
|
|
14
|
+
"Connection": "close",
|
|
15
|
+
"Pragma": "no-cache",
|
|
16
|
+
"Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
17
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
18
|
+
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
19
|
+
"Sec-Fetch-Dest": "document",
|
|
20
|
+
"Sec-Fetch-Mode": "navigate",
|
|
21
|
+
"Sec-Fetch-Site": "none",
|
|
22
|
+
"Sec-Fetch-User": "?1",
|
|
23
|
+
"Upgrade-Insecure-Requests": "1",
|
|
24
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
25
|
+
}
|
|
26
|
+
def search_by_place_id(cursor: str, place_id: str, location_name: str, currency:str, locale: str, check_in:str, check_out:str, api_key:str, proxy_url:str):
|
|
27
|
+
query_params = {
|
|
28
|
+
"operationName": "ExperiencesSearch",
|
|
29
|
+
"locale": locale,
|
|
30
|
+
"currency": currency,
|
|
31
|
+
}
|
|
32
|
+
url_parsed = f"{ep_search}?{urlencode(query_params)}"
|
|
33
|
+
rawParams=[
|
|
34
|
+
{"filterName":"cdnCacheSafe","filterValues":["false"]},
|
|
35
|
+
{"filterName":"checkin","filterValues":[check_in]},
|
|
36
|
+
{"filterName":"checkout","filterValues":[check_out]},
|
|
37
|
+
{"filterName":"datePickerType","filterValues":["calendar"]},
|
|
38
|
+
{"filterName":"federatedSearchSessionId","filterValues":[str(uuid.uuid4())]},
|
|
39
|
+
{"filterName":"flexibleTripLengths","filterValues":["one_week"]},
|
|
40
|
+
{"filterName":"isOnlineExperiences","filterValues":["false"]},
|
|
41
|
+
{"filterName":"itemsPerGrid","filterValues":["24"]},
|
|
42
|
+
{"filterName":"location","filterValues":[location_name]},
|
|
43
|
+
{"filterName":"monthlyEndDate","filterValues":["2025-05-01"]},
|
|
44
|
+
{"filterName":"monthlyLength","filterValues":["3"]},
|
|
45
|
+
{"filterName":"monthlyStartDate","filterValues":["2025-02-01"]},
|
|
46
|
+
{"filterName":"placeId","filterValues":[place_id]},
|
|
47
|
+
{"filterName":"query","filterValues":[location_name]},
|
|
48
|
+
{"filterName":"rankMode","filterValues":["default"]},
|
|
49
|
+
{"filterName":"refinementPaths","filterValues":["/experiences"]},
|
|
50
|
+
{"filterName":"screenSize","filterValues":["large"]},
|
|
51
|
+
{"filterName":"searchType","filterValues":["filter_change"]},
|
|
52
|
+
{"filterName":"source","filterValues":["structured_search_input_header"]},
|
|
53
|
+
{"filterName":"tabId","filterValues":["experience_tab"]},
|
|
54
|
+
{"filterName":"version","filterValues":["1.8.3"]}
|
|
55
|
+
]
|
|
56
|
+
inputData = {
|
|
57
|
+
"operationName":"ExperiencesSearch",
|
|
58
|
+
"extensions":{
|
|
59
|
+
"persistedQuery": {
|
|
60
|
+
"version": 1,
|
|
61
|
+
"sha256Hash": "fbbf9989cdf264a11fce48073008bb557f7f6b43961ccda5df6a8d988bd6ef36",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
"variables":{
|
|
65
|
+
"isLeanTreatment": False,
|
|
66
|
+
"experiencesSearchRequest": {
|
|
67
|
+
"metadataOnly": False,
|
|
68
|
+
"rawParams": rawParams,
|
|
69
|
+
"searchType": "filter_change",
|
|
70
|
+
"source": "structured_search_input_header",
|
|
71
|
+
"treatmentFlags":[
|
|
72
|
+
"stays_search_rehydration_treatment_desktop",
|
|
73
|
+
"stays_search_rehydration_treatment_moweb",
|
|
74
|
+
"experiences_search_feed_only_treatment",
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
if cursor!="":
|
|
80
|
+
inputData["variables"]["experiencesSearchRequest"]["cursor"] = cursor
|
|
81
|
+
headers_copy = headers.copy()
|
|
82
|
+
headers_copy["X-Airbnb-Api-Key"] = api_key
|
|
83
|
+
proxies = {}
|
|
84
|
+
if proxy_url:
|
|
85
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
86
|
+
response = requests.post(url_parsed, json = inputData, headers=headers_copy, proxies=proxies, impersonate="chrome124")
|
|
87
|
+
if response.status_code != 200:
|
|
88
|
+
raise Exception("Not corret status code: ", response.status_code, " response body: ",response.text)
|
|
89
|
+
data = response.json()
|
|
90
|
+
to_return=utils.get_nested_value(data,"data.presentation.experiencesSearch.results.searchResults",{})
|
|
91
|
+
cursor=utils.get_nested_value(data,"data.presentation.experiencesSearch.results.paginationInfo.nextPageCursor","")
|
|
92
|
+
return to_return,cursor
|
pyairbnb/host.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
import pyairbnb.utils as utils
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
ep = "https://www.airbnb.com/api/v3/UserProfileBeehiveListingQuery/529ca816b8be0619618d48b31bf46c379543e297fd68c0a953922927e5497b43"
|
|
7
|
+
|
|
8
|
+
extension = {
|
|
9
|
+
"persistedQuery": {
|
|
10
|
+
"version": 1,
|
|
11
|
+
"sha256Hash": "529ca816b8be0619618d48b31bf46c379543e297fd68c0a953922927e5497b43",
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
extensionRaw = json.dumps(extension)
|
|
16
|
+
|
|
17
|
+
def get_listings_from_user(userId: int, api_key: str, proxy_url: str):
|
|
18
|
+
offset = 0
|
|
19
|
+
all_listings = []
|
|
20
|
+
while True:
|
|
21
|
+
listings = get_listings_from_offset(offset, userId, api_key, proxy_url)
|
|
22
|
+
offset = offset + len(listings)
|
|
23
|
+
if len(listings)==0:
|
|
24
|
+
break
|
|
25
|
+
all_listings = all_listings + listings
|
|
26
|
+
return all_listings
|
|
27
|
+
|
|
28
|
+
def get_listings_from_offset(offset: int, userId: int, api_key: str, proxy_url: str) -> str:
|
|
29
|
+
variables = {
|
|
30
|
+
"userId": userId,
|
|
31
|
+
"limit": 12,
|
|
32
|
+
"offset": offset,
|
|
33
|
+
}
|
|
34
|
+
variablesRaw = json.dumps(variables)
|
|
35
|
+
query_params = {
|
|
36
|
+
"operationName": "UserProfileBeehiveListingQuery",
|
|
37
|
+
"locale": "en",
|
|
38
|
+
"currency":"USD",
|
|
39
|
+
"variables":variablesRaw,
|
|
40
|
+
"extensions":extensionRaw,
|
|
41
|
+
}
|
|
42
|
+
url_parsed = f"{ep}?{urlencode(query_params)}"
|
|
43
|
+
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else None
|
|
44
|
+
headers = {
|
|
45
|
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
|
46
|
+
"Accept-Language": "en",
|
|
47
|
+
"Cache-Control": "no-cache",
|
|
48
|
+
"Pragma": "no-cache",
|
|
49
|
+
"Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
|
|
50
|
+
"Sec-Ch-Ua-Mobile": "?0",
|
|
51
|
+
"Sec-Ch-Ua-Platform": '"Windows"',
|
|
52
|
+
"Sec-Fetch-Dest": "document",
|
|
53
|
+
"Sec-Fetch-Mode": "navigate",
|
|
54
|
+
"Sec-Fetch-Site": "none",
|
|
55
|
+
"X-Airbnb-Api-Key": api_key,
|
|
56
|
+
"Sec-Fetch-User": "?1",
|
|
57
|
+
"Upgrade-Insecure-Requests": "1",
|
|
58
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
59
|
+
}
|
|
60
|
+
response = requests.get(url_parsed, headers=headers, proxies=proxies, timeout=60)
|
|
61
|
+
response.raise_for_status()
|
|
62
|
+
data = response.json()
|
|
63
|
+
listings = utils.get_nested_value(data,"data.beehive.getListOfListings.listings",[])
|
|
64
|
+
return listings
|
pyairbnb/host_details.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
import json
|
|
4
|
+
import base64
|
|
5
|
+
|
|
6
|
+
def get(host_id: str, api_key: str, proxy_url: str, cookies):
|
|
7
|
+
# Encode the host ID to match Airbnb's required format
|
|
8
|
+
host_id = 'User:' + host_id
|
|
9
|
+
user_id = base64.b64encode(host_id.encode()).decode('utf-8')
|
|
10
|
+
|
|
11
|
+
# Set up headers
|
|
12
|
+
headers = {
|
|
13
|
+
"Accept": "application/json",
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
16
|
+
"X-Airbnb-Api-Key": api_key,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Set up parameters
|
|
20
|
+
params = {
|
|
21
|
+
'operationName': 'GetUserProfile',
|
|
22
|
+
'locale': 'en',
|
|
23
|
+
'currency': 'USD',
|
|
24
|
+
'variables': json.dumps({
|
|
25
|
+
"userId": user_id,
|
|
26
|
+
"isPassportStampsEnabled": True,
|
|
27
|
+
"mockIdentifier": None,
|
|
28
|
+
"fetchCombinedSportsAndInterests": True
|
|
29
|
+
}),
|
|
30
|
+
'extensions': json.dumps({
|
|
31
|
+
"persistedQuery": {
|
|
32
|
+
"version": 1,
|
|
33
|
+
"sha256Hash": "a56d8909f271740ccfef23dd6c34d098f194f4a6e7157f244814c5610b8ad76a"
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Set up proxy if available
|
|
39
|
+
proxies = {"http": proxy_url, "https": proxy_url} if proxy_url else {}
|
|
40
|
+
|
|
41
|
+
# Make the GET request
|
|
42
|
+
response = requests.get(
|
|
43
|
+
'https://www.airbnb.com/api/v3/GetUserProfile/a56d8909f271740ccfef23dd6c34d098f194f4a6e7157f244814c5610b8ad76a',
|
|
44
|
+
params=params,
|
|
45
|
+
headers=headers,
|
|
46
|
+
cookies=cookies,
|
|
47
|
+
proxies=proxies
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# Raise an exception if the request failed
|
|
51
|
+
response.raise_for_status()
|
|
52
|
+
|
|
53
|
+
# Parse the response JSON
|
|
54
|
+
data = response.json()
|
|
55
|
+
|
|
56
|
+
return data
|
pyairbnb/parse.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import json
|
|
3
|
+
from bs4 import BeautifulSoup
|
|
4
|
+
import pyairbnb.standardize as standardize
|
|
5
|
+
import pyairbnb.utils as utils
|
|
6
|
+
|
|
7
|
+
regxApiKey = re.compile(r'"key":".+?"')
|
|
8
|
+
regexLanguage = re.compile(r'"language":".+?"')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def parse_body_details_wrapper(body:str):
|
|
12
|
+
data_raw, language, api_key = parse_body_details(body)
|
|
13
|
+
data_formatted = standardize.from_details(data_raw)
|
|
14
|
+
data_formatted["language"] = language
|
|
15
|
+
price_dependency_input={
|
|
16
|
+
"product_id": data_raw['variables']['id'],
|
|
17
|
+
"impression_id": data_raw['variables']['pdpSectionsRequest']['p3ImpressionId'],
|
|
18
|
+
"api_key": api_key
|
|
19
|
+
}
|
|
20
|
+
return data_formatted, price_dependency_input
|
|
21
|
+
|
|
22
|
+
def parse_body_details(body:str):
|
|
23
|
+
soup = BeautifulSoup(body, 'html.parser')
|
|
24
|
+
data_deferred_state = soup.select("#data-deferred-state-0")[0].getText()
|
|
25
|
+
html_data = utils.remove_space(data_deferred_state)
|
|
26
|
+
language = regexLanguage.search(body).group()
|
|
27
|
+
language = language.replace('"language":"', "")
|
|
28
|
+
language = language.replace('"', "")
|
|
29
|
+
api_key = regxApiKey.search(body).group()
|
|
30
|
+
api_key = api_key.replace('"key":"', "")
|
|
31
|
+
api_key = api_key.replace('"', "")
|
|
32
|
+
data = json.loads(html_data)
|
|
33
|
+
details_data = data["niobeMinimalClientData"][0][1]
|
|
34
|
+
return details_data, language, api_key
|
pyairbnb/price.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from curl_cffi import requests
|
|
3
|
+
import pyairbnb.utils as utils
|
|
4
|
+
from urllib.parse import urlencode
|
|
5
|
+
ep = "https://www.airbnb.com/api/v3/StaysPdpSections/80c7889b4b0027d99ffea830f6c0d4911a6e863a957cbe1044823f0fc746bf1f"
|
|
6
|
+
|
|
7
|
+
def get(product_id: str, impresion_id: str,api_key: str, currency: str, cookies: list, checkIn: str, checkOut: str, proxy_url: str) -> (str):
|
|
8
|
+
headers = {
|
|
9
|
+
"Accept": "application/json",
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
12
|
+
"X-Airbnb-Api-Key": api_key,
|
|
13
|
+
}
|
|
14
|
+
entension={
|
|
15
|
+
"persistedQuery": {
|
|
16
|
+
"version":1,
|
|
17
|
+
"sha256Hash": "80c7889b4b0027d99ffea830f6c0d4911a6e863a957cbe1044823f0fc746bf1f",
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
dataRawExtension = json.dumps(entension)
|
|
21
|
+
variablesData={
|
|
22
|
+
"id": product_id,
|
|
23
|
+
"pdpSectionsRequest": {
|
|
24
|
+
"adults": "1",
|
|
25
|
+
"bypassTargetings": False,
|
|
26
|
+
"categoryTag": None,
|
|
27
|
+
"causeId": None,
|
|
28
|
+
"children": None,
|
|
29
|
+
"disasterId": None,
|
|
30
|
+
"discountedGuestFeeVersion": None,
|
|
31
|
+
"displayExtensions": None,
|
|
32
|
+
"federatedSearchId": None,
|
|
33
|
+
"forceBoostPriorityMessageType": None,
|
|
34
|
+
"infants": None,
|
|
35
|
+
"interactionType": None,
|
|
36
|
+
"layouts": ["SIDEBAR", "SINGLE_COLUMN"],
|
|
37
|
+
"pets": 0,
|
|
38
|
+
"pdpTypeOverride": None,
|
|
39
|
+
"photoId": None,
|
|
40
|
+
"preview": False,
|
|
41
|
+
"previousStateCheckIn": None,
|
|
42
|
+
"previousStateCheckOut": None,
|
|
43
|
+
"priceDropSource": None,
|
|
44
|
+
"privateBooking": False,
|
|
45
|
+
"promotionUuid": None,
|
|
46
|
+
"relaxedAmenityIds": None,
|
|
47
|
+
"searchId": None,
|
|
48
|
+
"selectedCancellationPolicyId": None,
|
|
49
|
+
"selectedRatePlanId": None,
|
|
50
|
+
"splitStays": None,
|
|
51
|
+
"staysBookingMigrationEnabled": False,
|
|
52
|
+
"translateUgc": None,
|
|
53
|
+
"useNewSectionWrapperApi": False,
|
|
54
|
+
"sectionIds": ["BOOK_IT_FLOATING_FOOTER","POLICIES_DEFAULT","EDUCATION_FOOTER_BANNER_MODAL",
|
|
55
|
+
"BOOK_IT_SIDEBAR","URGENCY_COMMITMENT_SIDEBAR","BOOK_IT_NAV","MESSAGE_BANNER","HIGHLIGHTS_DEFAULT",
|
|
56
|
+
"EDUCATION_FOOTER_BANNER","URGENCY_COMMITMENT","BOOK_IT_CALENDAR_SHEET","CANCELLATION_POLICY_PICKER_MODAL"],
|
|
57
|
+
"checkIn": checkIn,
|
|
58
|
+
"checkOut": checkOut,
|
|
59
|
+
"p3ImpressionId": impresion_id,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
dataRawVariables = json.dumps(variablesData)
|
|
63
|
+
query = {
|
|
64
|
+
"operationName": "StaysPdpSections",
|
|
65
|
+
"locale": "en",
|
|
66
|
+
"currency": currency,
|
|
67
|
+
"variables": dataRawVariables,
|
|
68
|
+
"extensions": dataRawExtension,
|
|
69
|
+
}
|
|
70
|
+
url = f"{ep}?{urlencode(query)}"
|
|
71
|
+
|
|
72
|
+
session = requests.Session()
|
|
73
|
+
proxies = {}
|
|
74
|
+
if proxy_url:
|
|
75
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
76
|
+
|
|
77
|
+
for name in cookies:
|
|
78
|
+
session.cookies.set(name, cookies[name])
|
|
79
|
+
|
|
80
|
+
response = session.get(url, headers=headers, proxies=proxies)
|
|
81
|
+
response.raise_for_status()
|
|
82
|
+
|
|
83
|
+
data = response.json()
|
|
84
|
+
|
|
85
|
+
sections = utils.get_nested_value(data,"data.presentation.stayProductDetailPage.sections.sections",{})
|
|
86
|
+
for section in sections:
|
|
87
|
+
if section['sectionId'] == "BOOK_IT_SIDEBAR":
|
|
88
|
+
price_data = utils.get_nested_value(section,"section.structuredDisplayPrice",{})
|
|
89
|
+
finalData={
|
|
90
|
+
"main":{
|
|
91
|
+
"price":utils.get_nested_value(price_data,"primaryLine.price",{}),
|
|
92
|
+
"discountedPrice":utils.get_nested_value(price_data,"primaryLine.discountedPrice",{}),
|
|
93
|
+
"originalPrice":utils.get_nested_value(price_data,"primaryLine.originalPrice",{}),
|
|
94
|
+
"qualifier":utils.get_nested_value(price_data,"primaryLine.qualifier",{}),
|
|
95
|
+
},
|
|
96
|
+
"details":{},
|
|
97
|
+
}
|
|
98
|
+
details = utils.get_nested_value(price_data,"explanationData.priceDetails",{})
|
|
99
|
+
for detail in details:
|
|
100
|
+
for item in utils.get_nested_value(detail,"items",{}):
|
|
101
|
+
finalData["details"][item["description"]]=item["priceString"]
|
|
102
|
+
return finalData
|
|
103
|
+
return {}
|
pyairbnb/reviews.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from curl_cffi import requests
|
|
2
|
+
import pyairbnb.utils as utils
|
|
3
|
+
from urllib.parse import urlencode
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
ep="https://www.airbnb.com/api/v3/StaysPdpReviewsQuery/dec1c8061483e78373602047450322fd474e79ba9afa8d3dbbc27f504030f91d/"
|
|
7
|
+
|
|
8
|
+
def get(product_id: str, api_key: str,proxy_url: str) -> str:
|
|
9
|
+
offset = 0
|
|
10
|
+
all_reviews = []
|
|
11
|
+
while True:
|
|
12
|
+
reviews = get_from_offset(offset,product_id,api_key,proxy_url)
|
|
13
|
+
offset=offset+50
|
|
14
|
+
if len(reviews)==0:
|
|
15
|
+
break
|
|
16
|
+
all_reviews.extend(reviews)
|
|
17
|
+
return all_reviews
|
|
18
|
+
|
|
19
|
+
def get_from_offset(offset: int,product_id: str, api_key: str,proxy_url: str) -> str:
|
|
20
|
+
headers = {
|
|
21
|
+
"Accept": "application/json",
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
24
|
+
"X-Airbnb-Api-Key": api_key,
|
|
25
|
+
}
|
|
26
|
+
variablesData={
|
|
27
|
+
"id": product_id,
|
|
28
|
+
"pdpReviewsRequest":{
|
|
29
|
+
"fieldSelector": "for_p3_translation_only",
|
|
30
|
+
"forPreview": False,
|
|
31
|
+
"limit": 50,
|
|
32
|
+
"offset": f"{offset}",
|
|
33
|
+
"showingTranslationButton": False,
|
|
34
|
+
"first": 50,
|
|
35
|
+
"sortingPreference": "MOST_RECENT",
|
|
36
|
+
"numberOfAdults": "1",
|
|
37
|
+
"numberOfChildren": "0",
|
|
38
|
+
"numberOfInfants": "0",
|
|
39
|
+
"numberOfPets": "0",
|
|
40
|
+
"after": None,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
entension={
|
|
44
|
+
"persistedQuery": {
|
|
45
|
+
"version":1,
|
|
46
|
+
"sha256Hash": "dec1c8061483e78373602047450322fd474e79ba9afa8d3dbbc27f504030f91d",
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
dataRawExtension = json.dumps(entension)
|
|
50
|
+
dataRawVariables = json.dumps(variablesData)
|
|
51
|
+
query = {
|
|
52
|
+
"operationName": "StaysPdpReviewsQuery",
|
|
53
|
+
"locale": "en",
|
|
54
|
+
"currency": "USD",
|
|
55
|
+
"variables": dataRawVariables,
|
|
56
|
+
"extensions": dataRawExtension,
|
|
57
|
+
}
|
|
58
|
+
url = f"{ep}?{urlencode(query)}"
|
|
59
|
+
proxies = {}
|
|
60
|
+
if proxy_url:
|
|
61
|
+
proxies = {"http": proxy_url, "https": proxy_url}
|
|
62
|
+
response = requests.get(url, headers=headers, proxies=proxies, timeout=60)
|
|
63
|
+
response.raise_for_status()
|
|
64
|
+
data = response.json()
|
|
65
|
+
reviews = utils.get_nested_value(data,"data.presentation.stayProductDetailPage.reviews.reviews",{})
|
|
66
|
+
return reviews
|