pyairbnb 0.0.0__tar.gz

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-0.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 John
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyairbnb
3
+ Version: 0.0.0
4
+ Summary: Airbnb scraper in Python
5
+ Home-page: https://github.com/johnbalvin/pyairbnb
6
+ Author: John (John Balvin)
7
+ Author-email: John Balvin <johnchristian@hotmail.es>
8
+ Project-URL: Homepage, https://github.com/johnbalvin/pyairbnb
9
+ Keywords: airbnb,scraper,crawler,bot,reviews
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: curl_cffi
13
+ Requires-Dist: bs4
14
+ Requires-Dist: requests
15
+
16
+ # Airbnb scraper in Python
17
+
18
+ ## Overview
19
+ This project is an open-source tool developed in Python for extracting product information from Airbnb. It's designed to be easy to use, making it an ideal solution for developers looking for Airbnb product data.
20
+
21
+ ## Features
22
+ - Extract prices, available dates, reviews and others
23
+ - Full search support
24
+ - Extracts detailed product information from Airbnb
25
+ - Implemented in Python just because it's popular
26
+ - Easy to integrate with existing Python projects
27
+ - The code is optimize to work on this format: ```https://www.airbnb.com/rooms/[room_id]```
28
+
29
+ ## Important
30
+ - With the new airbnb changes, if you want to get the price from a room url you need to specify the date range
31
+ the date range should be on the format year-month-day, if you leave the date range empty, you will get the details but not the price
32
+
33
+
34
+ ### Install
35
+
36
+ ```bash
37
+ $ pip install pyairbnb
38
+ ```
39
+ ## Examples
40
+
41
+ ```Python
42
+ import pyairbnb
43
+ import json
44
+ currency="MXN"
45
+ check_in = "2025-02-01"
46
+ check_out = "2025-02-04"
47
+ ne_lat = -1.03866277790021
48
+ ne_long = -77.53091734683608
49
+ sw_lat = -1.1225978433925647
50
+ sw_long = -77.59713412765507
51
+ zoom_value = 2
52
+ search_results = pyairbnb.search_all(check_in,check_out,ne_lat,ne_long,sw_lat,sw_long,zoom_value, currency,"")
53
+ details_data = []
54
+ progress = 1
55
+ with open('search_results.json', 'w', encoding='utf-8') as f:
56
+ f.write(json.dumps(search_results))
57
+ for result in search_results[:10]:
58
+ data = pyairbnb.get_details_from_id(result["room_id"],currency,check_in,check_out,"")
59
+ details_data.append(data)
60
+ print("len results: ",progress, len(search_results))
61
+ progress=progress+1
62
+
63
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
64
+ f.write(json.dumps(details_data))
65
+ ```
66
+
67
+ ### Example for getting prices, avaiable dates, reviews and other metadata
68
+
69
+ ### Getting the reviews, along with metadata
70
+ ```Python
71
+ import pyairbnb
72
+ import json
73
+ room_url="https://www.airbnb.com/rooms/30931885"
74
+ data = pyairbnb.get_reviews(room_url,"")
75
+ with open('reviews.json', 'w', encoding='utf-8') as f:
76
+ f.write(json.dumps(data["reviews"]))
77
+ ```
78
+
79
+ ### Getting just the available/unavailable dates
80
+ ```Python
81
+ import pyairbnb
82
+ import json
83
+ room_url="https://www.airbnb.com/rooms/44590727"
84
+ calendar = pyairbnb.get_calendar(room_url,"")
85
+ with open('calendar.json', 'w', encoding='utf-8') as f:
86
+ f.write(json.dumps(calendar["calendar"]))
87
+ ```
88
+
89
+ ### if you want to get the price you need to send the check in and check out date(this is a requirement on airbn itself)
90
+ ```Python
91
+ import pyairbnb
92
+ import json
93
+ room_url="https://www.airbnb.com/rooms/43198150"
94
+ currency="USD"
95
+ check_in = "2025-01-02"
96
+ check_out = "2025-01-04"
97
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
98
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
99
+ f.write(json.dumps(data))
100
+ ```
101
+
102
+
103
+ ### example for getting details and NOT price
104
+ ### if you won't want the price, you can just leave it empty
105
+ ```Python
106
+ import pyairbnb
107
+ import json
108
+ room_url="https://www.airbnb.com/rooms/1029961446117217643"
109
+ currency="USD"
110
+ check_in = ""
111
+ check_out = ""
112
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
113
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
114
+ f.write(json.dumps(data))
115
+ ```
116
+
117
+ ```Python
118
+ import pyairbnb
119
+ import json
120
+ room_id=18039593#the room id
121
+ currency="MXN"
122
+ check_in = ""
123
+ check_out = ""
124
+ proxy_url = pyairbnb.parse_proxy("[IP or domain]","[port]","[user name]","[password]")
125
+ data = pyairbnb.get_details_from_id(room_id,currency,check_in,check_out,proxy_url)
126
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
127
+ f.write(json.dumps(data))
128
+ ```
@@ -0,0 +1,113 @@
1
+ # Airbnb scraper in Python
2
+
3
+ ## Overview
4
+ This project is an open-source tool developed in Python for extracting product information from Airbnb. It's designed to be easy to use, making it an ideal solution for developers looking for Airbnb product data.
5
+
6
+ ## Features
7
+ - Extract prices, available dates, reviews and others
8
+ - Full search support
9
+ - Extracts detailed product information from Airbnb
10
+ - Implemented in Python just because it's popular
11
+ - Easy to integrate with existing Python projects
12
+ - The code is optimize to work on this format: ```https://www.airbnb.com/rooms/[room_id]```
13
+
14
+ ## Important
15
+ - With the new airbnb changes, if you want to get the price from a room url you need to specify the date range
16
+ the date range should be on the format year-month-day, if you leave the date range empty, you will get the details but not the price
17
+
18
+
19
+ ### Install
20
+
21
+ ```bash
22
+ $ pip install pyairbnb
23
+ ```
24
+ ## Examples
25
+
26
+ ```Python
27
+ import pyairbnb
28
+ import json
29
+ currency="MXN"
30
+ check_in = "2025-02-01"
31
+ check_out = "2025-02-04"
32
+ ne_lat = -1.03866277790021
33
+ ne_long = -77.53091734683608
34
+ sw_lat = -1.1225978433925647
35
+ sw_long = -77.59713412765507
36
+ zoom_value = 2
37
+ search_results = pyairbnb.search_all(check_in,check_out,ne_lat,ne_long,sw_lat,sw_long,zoom_value, currency,"")
38
+ details_data = []
39
+ progress = 1
40
+ with open('search_results.json', 'w', encoding='utf-8') as f:
41
+ f.write(json.dumps(search_results))
42
+ for result in search_results[:10]:
43
+ data = pyairbnb.get_details_from_id(result["room_id"],currency,check_in,check_out,"")
44
+ details_data.append(data)
45
+ print("len results: ",progress, len(search_results))
46
+ progress=progress+1
47
+
48
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
49
+ f.write(json.dumps(details_data))
50
+ ```
51
+
52
+ ### Example for getting prices, avaiable dates, reviews and other metadata
53
+
54
+ ### Getting the reviews, along with metadata
55
+ ```Python
56
+ import pyairbnb
57
+ import json
58
+ room_url="https://www.airbnb.com/rooms/30931885"
59
+ data = pyairbnb.get_reviews(room_url,"")
60
+ with open('reviews.json', 'w', encoding='utf-8') as f:
61
+ f.write(json.dumps(data["reviews"]))
62
+ ```
63
+
64
+ ### Getting just the available/unavailable dates
65
+ ```Python
66
+ import pyairbnb
67
+ import json
68
+ room_url="https://www.airbnb.com/rooms/44590727"
69
+ calendar = pyairbnb.get_calendar(room_url,"")
70
+ with open('calendar.json', 'w', encoding='utf-8') as f:
71
+ f.write(json.dumps(calendar["calendar"]))
72
+ ```
73
+
74
+ ### if you want to get the price you need to send the check in and check out date(this is a requirement on airbn itself)
75
+ ```Python
76
+ import pyairbnb
77
+ import json
78
+ room_url="https://www.airbnb.com/rooms/43198150"
79
+ currency="USD"
80
+ check_in = "2025-01-02"
81
+ check_out = "2025-01-04"
82
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
83
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
84
+ f.write(json.dumps(data))
85
+ ```
86
+
87
+
88
+ ### example for getting details and NOT price
89
+ ### if you won't want the price, you can just leave it empty
90
+ ```Python
91
+ import pyairbnb
92
+ import json
93
+ room_url="https://www.airbnb.com/rooms/1029961446117217643"
94
+ currency="USD"
95
+ check_in = ""
96
+ check_out = ""
97
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
98
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
99
+ f.write(json.dumps(data))
100
+ ```
101
+
102
+ ```Python
103
+ import pyairbnb
104
+ import json
105
+ room_id=18039593#the room id
106
+ currency="MXN"
107
+ check_in = ""
108
+ check_out = ""
109
+ proxy_url = pyairbnb.parse_proxy("[IP or domain]","[port]","[user name]","[password]")
110
+ data = pyairbnb.get_details_from_id(room_id,currency,check_in,check_out,proxy_url)
111
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
112
+ f.write(json.dumps(data))
113
+ ```
@@ -0,0 +1,15 @@
1
+ [project]
2
+
3
+ version = '0.0.0'
4
+ name="pyairbnb"
5
+ description = 'Airbnb scraper in Python'
6
+ authors = [
7
+ { name="John Balvin", email="johnchristian@hotmail.es" },
8
+ ]
9
+ readme= "README.md"
10
+ keywords=['airbnb', 'scraper', 'crawler','bot','reviews']
11
+ dependencies=['curl_cffi','bs4','requests']
12
+
13
+
14
+ [project.urls]
15
+ Homepage='https://github.com/johnbalvin/pyairbnb'
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup
2
+
3
+ VERSION = '0.0.0'
4
+ DESCRIPTION = 'Airbnb scraper in Python'
5
+
6
+ setup(
7
+ name="pyairbnb",
8
+ version=VERSION,
9
+ author="John (John Balvin)",
10
+ author_email="<johnchristian@hotmail.es>",
11
+ description=DESCRIPTION,
12
+ long_description_content_type="text/markdown",
13
+ url='https://github.com/johnbalvin/pyairbnb',
14
+ long_description=open('README.md').read(),
15
+ keywords=['airbnb', 'scraper', 'crawler','bot','reviews'],
16
+ install_requires=['curl_cffi','bs4'],
17
+ )
@@ -0,0 +1,2 @@
1
+ from pyairbnb.utils import parse_proxy
2
+ from pyairbnb.start import get_calendar,search_all,search_first_page,get_reviews,get_details_from_url,get_details_from_id,get_details_from_id_and_domain
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 {}
@@ -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
@@ -0,0 +1,111 @@
1
+ from datetime import datetime
2
+ from urllib.parse import urlencode
3
+ import pyairbnb.utils as utils
4
+ from curl_cffi import requests
5
+
6
+ treament = [
7
+ "feed_map_decouple_m11_treatment",
8
+ "stays_search_rehydration_treatment_desktop",
9
+ "stays_search_rehydration_treatment_moweb",
10
+ "selective_query_feed_map_homepage_desktop_treatment",
11
+ "selective_query_feed_map_homepage_moweb_treatment",
12
+ ]
13
+
14
+
15
+
16
+ def get(check_in:str, check_out:str, ne_lat:float, ne_long:float, sw_lat:float, sw_long:float, zoom_value:int, cursor:str, currency:str, api_key:str, proxy_url:str):
17
+ check_in_date = datetime.strptime(check_in, "%Y-%m-%d")
18
+ check_out_date = datetime.strptime(check_out, "%Y-%m-%d")
19
+
20
+ difference = check_out_date - check_in_date
21
+
22
+ days = difference.days
23
+
24
+ base_url = "https://www.airbnb.com/api/v3/StaysSearch/d4d9503616dc72ab220ed8dcf17f166816dccb2593e7b4625c91c3fce3a3b3d6"
25
+ query_params = {
26
+ "operationName": "StaysSearch",
27
+ "locale": "en",
28
+ "currency": currency,
29
+ }
30
+ url_parsed = f"{base_url}?{urlencode(query_params)}"
31
+ rawParams=[
32
+ {"filterName":"cdnCacheSafe","filterValues":["false"]},
33
+ {"filterName":"channel","filterValues":["EXPLORE"]},
34
+ {"filterName":"checkin","filterValues":[check_in]},
35
+ {"filterName":"checkout","filterValues":[check_out]},
36
+ {"filterName":"datePickerType","filterValues":["calendar"]},
37
+ {"filterName":"flexibleTripLengths","filterValues":["one_week"]},
38
+ {"filterName":"itemsPerGrid","filterValues":["50"]},#if you read this, this is items returned number, this can bex exploited ;)
39
+ {"filterName":"monthlyLength","filterValues":["3"]},
40
+ {"filterName":"monthlyStartDate","filterValues":["2024-02-01"]},
41
+ {"filterName":"neLat","filterValues":[str(ne_lat)]},
42
+ {"filterName":"neLng","filterValues":[str(ne_long)]},
43
+ {"filterName":"placeId","filterValues":["ChIJpTeBx6wjq5oROJeXkPCSSSo"]},
44
+ {"filterName":"priceFilterInputType","filterValues":["0"]},
45
+ {"filterName":"priceFilterNumNights","filterValues":[str(days)]},
46
+ {"filterName":"query","filterValues":["Galapagos Island, Ecuador"]},
47
+ {"filterName":"screenSize","filterValues":["large"]},
48
+ {"filterName":"refinementPaths","filterValues":["/homes"]},
49
+ {"filterName":"searchByMap","filterValues":["true"]},
50
+ {"filterName":"swLat","filterValues":[str(sw_lat)]},
51
+ {"filterName":"swLng","filterValues":[str(sw_long)]},
52
+ {"filterName":"tabId","filterValues":["home_tab"]},
53
+ {"filterName":"version","filterValues":["1.8.3"]},
54
+ {"filterName":"zoomLevel","filterValues":[str(zoom_value)]},
55
+ ]
56
+ inputData = {
57
+ "operationName":"StaysSearch",
58
+ "extensions":{
59
+ "persistedQuery": {
60
+ "version": 1,
61
+ "sha256Hash": "d4d9503616dc72ab220ed8dcf17f166816dccb2593e7b4625c91c3fce3a3b3d6",
62
+ },
63
+ },
64
+ "variables":{
65
+ "includeMapResults": True,
66
+ "isLeanTreatment": False,
67
+ "staysMapSearchRequestV2": {
68
+ "cursor":cursor,
69
+ "requestedPageType":"STAYS_SEARCH",
70
+ "metadataOnly":False,
71
+ "source":"structured_search_input_header",
72
+ "searchType":"user_map_move",
73
+ "treatmentFlags":treament,
74
+ "rawParams":rawParams,
75
+ },
76
+ "staysSearchRequest": {
77
+ "cursor":cursor,
78
+ "maxMapItems": 9999,
79
+ "requestedPageType":"STAYS_SEARCH",
80
+ "metadataOnly":False,
81
+ "source":"structured_search_input_header",
82
+ "searchType":"user_map_move",
83
+ "treatmentFlags":treament,
84
+ "rawParams":rawParams,
85
+ },
86
+ },
87
+ }
88
+ headers = {
89
+ "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",
90
+ "Accept-Language": "en",
91
+ "Cache-Control": "no-cache",
92
+ "Connection": "close",
93
+ "Pragma": "no-cache",
94
+ "Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
95
+ "Sec-Ch-Ua-Mobile": "?0",
96
+ "X-Airbnb-Api-Key": api_key,
97
+ "Sec-Ch-Ua-Platform": '"Windows"',
98
+ "Sec-Fetch-Dest": "document",
99
+ "Sec-Fetch-Mode": "navigate",
100
+ "Sec-Fetch-Site": "none",
101
+ "Sec-Fetch-User": "?1",
102
+ "Upgrade-Insecure-Requests": "1",
103
+ "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"
104
+ }
105
+ proxies = {}
106
+ if proxy_url:
107
+ proxies = {"http": proxy_url, "https": proxy_url}
108
+ response = requests.post(url_parsed, json = inputData, headers=headers, proxies=proxies, impersonate="chrome110")
109
+ data = response.json()
110
+ to_return=utils.get_nested_value(data,"data.presentation.staysSearch.results",{})
111
+ return to_return
@@ -0,0 +1,233 @@
1
+ import re
2
+ import pyairbnb.utils as utils
3
+
4
+ regex_number = re.compile(r'\d+')
5
+
6
+ def from_search(results):
7
+ datas = []
8
+ for result in results:
9
+ type_name = utils.get_nested_value(result,"__typename","")
10
+ if type_name!="StaySearchResult":
11
+ continue
12
+ lt = utils.get_nested_value(result,"listing",{})
13
+ pr = utils.get_nested_value(result,"pricingQuote.structuredStayDisplayPrice",{})
14
+ data = {
15
+ "room_id": int(lt["id"]),
16
+ "category": utils.get_nested_value(lt,"roomTypeCategory",""),
17
+ "kind": utils.get_nested_value(lt,"pdpUrlType",""),
18
+ "name": utils.get_nested_value(lt,"name",""),
19
+ "title": utils.get_nested_value(lt,"title",""),
20
+ "type": utils.get_nested_value(lt,"listingObjType",""),
21
+ "long_stay_discount":{},
22
+ "fee":{
23
+ "airbnb":{},
24
+ "cleaning":{},
25
+ },
26
+ "price": {
27
+ "unit":{
28
+ "qualifier": utils.get_nested_value(pr,"primaryLine.qualifier","")
29
+ },
30
+ "total":{},
31
+ "break_down":[],
32
+ },
33
+ "rating":{
34
+ "value":0,
35
+ "reviewCount": 0,
36
+ },
37
+ "images": [],
38
+ "badges": [],
39
+ "coordinates":{
40
+ "latitude": utils.get_nested_value(lt,"coordinate.latitude",0),
41
+ "longitud": utils.get_nested_value(lt,"coordinate.longitude",0),
42
+ },
43
+ }
44
+ for badge in utils.get_nested_value(lt,"formattedBadges",[]):
45
+ data["badges"].append(utils.get_nested_value(badge,"loggingContext.badgeType",""))
46
+
47
+ avgRatingLocalized = utils.get_nested_value(lt,"avgRatingLocalized","")
48
+ splited = avgRatingLocalized.split(" ")
49
+ if len(splited)==2:
50
+ rating = float(splited[0])
51
+ data["rating"]["value"]=rating
52
+ reviewCount = regex_number.search(splited[1]).group()
53
+ data["rating"]["reviewCount"]=reviewCount
54
+ price_to_use = utils.get_nested_value(pr,"primaryLine.originalPrice","")
55
+ if price_to_use=="":
56
+ price_to_use = utils.get_nested_value(pr,"primaryLine.price","")
57
+
58
+ if price_to_use!="":
59
+ amount, currency = utils.parse_price_symbol(price_to_use)
60
+ data["price"]["unit"]["curency_symbol"]=currency
61
+ data["price"]["unit"]["amount"]=amount
62
+
63
+ discountedPrice=utils.get_nested_value(pr,"primaryLine.discountedPrice","")
64
+ if discountedPrice!="":
65
+ amount, _ = utils.parse_price_symbol(discountedPrice)
66
+ data["price"]["unit"]["discount"]=amount
67
+
68
+ splited = utils.get_nested_value(pr,"secondaryLine.price","").split(" ")
69
+ price_to_use=""
70
+ match len(splited):
71
+ case 1:
72
+ if len(splited[0])!=0:
73
+ print("price error: ",splited )
74
+ case 2:
75
+ price_to_use=splited[0]
76
+ case 3:
77
+ splited = splited[:len(splited)-1]
78
+ price_to_use = "".join(splited)
79
+ case _:
80
+ continue
81
+
82
+ amount, currency = utils.parse_price_symbol(price_to_use)
83
+ data["price"]["total"]["currency_symbol"]=currency
84
+ data["price"]["total"]["amount"]=amount
85
+ for image_data in utils.get_nested_value(lt,"contextualPictures",[]):
86
+ img={"url": utils.get_nested_value(image_data,"picture","")}
87
+ data["images"].append(img)
88
+ for price_detail in utils.get_nested_value(pr,"explanationData.priceDetails",[]):
89
+ if "items" not in price_detail:
90
+ continue
91
+ for item in utils.get_nested_value(price_detail,"items",[]):
92
+ amount, currency = utils.parse_price_symbol(item["priceString"])
93
+ data["price"]["break_down"].append({"description":item["description"],"amount":amount,"currency":currency})
94
+ match item["displayComponentType"]:
95
+ case "DISCOUNTED_EXPLANATION_LINE_ITEM":
96
+ match item["description"]:
97
+ case "Long stay discount":
98
+ data["long_stay_discount"]["amount"]=amount
99
+ data["long_stay_discount"]["currency_symbol"]=currency
100
+ case "DEFAULT_EXPLANATION_LINE_ITEM":
101
+ match item["description"]:
102
+ case "Cleaning fee":
103
+ data["fee"]["cleaning"]["amount"]=amount
104
+ data["fee"]["cleaning"]["currency_symbol"]=currency
105
+ case "Airbnb service fee":
106
+ data["fee"]["airbnb"]["amount"]=amount
107
+ data["fee"]["airbnb"]["currency_symbol"]=currency
108
+ datas.append(data)
109
+
110
+ return datas
111
+
112
+
113
+ def from_details(meta):
114
+ ev = meta["data"]["presentation"]["stayProductDetailPage"]["sections"]["metadata"]["loggingContext"]["eventDataLogging"]
115
+ data = {
116
+ "coordinates": {
117
+ "latitude": utils.get_nested_value(ev,"listingLat",0),
118
+ "longitude": utils.get_nested_value(ev,"listingLng",0),
119
+ },
120
+ "room_type": utils.get_nested_value(ev,"roomType",""),
121
+ "is_super_host": utils.get_nested_value(ev,"isSuperhost",""),
122
+ "home_tier": utils.get_nested_value(ev,"homeTier",""),
123
+ "person_capacity": utils.get_nested_value(ev,"personCapacity",0),
124
+ "rating":{
125
+ "accuracy": utils.get_nested_value(ev,"accuracyRating",0),
126
+ "checking": utils.get_nested_value(ev,"checkinRating",0),
127
+ "cleanliness": utils.get_nested_value(ev,"cleanlinessRating",0),
128
+ "communication": utils.get_nested_value(ev,"communicationRating",0),
129
+ "location": utils.get_nested_value(ev,"locationRating",0),
130
+ "value": utils.get_nested_value(ev,"valueRating",0),
131
+ "guest_satisfaction": utils.get_nested_value(ev,"guestSatisfactionOverall",0),
132
+ "review_count": utils.get_nested_value(ev,"visibleReviewCount",0),
133
+ },
134
+ "house_rules":{
135
+ "aditional":"",
136
+ "general": [],
137
+ },
138
+ "host":{
139
+ "id":"",
140
+ "name":"",
141
+ "joined_on":"",
142
+ "description":"",
143
+ },
144
+ "sub_description":{
145
+ "title":"",
146
+ "items": [],
147
+ },
148
+ "amenities": [],
149
+ "co_hosts":[],
150
+ "images":[],
151
+ "location_descriptions":[],
152
+ "highlights":[],
153
+ }
154
+
155
+ sd = utils.get_nested_value(meta,"data.presentation.stayProductDetailPage.sections.sbuiData")
156
+ for section in utils.get_nested_value(sd,"sectionConfiguration.root.sections",[]):
157
+ typeName=utils.get_nested_value(section,"sectionData.__typename","")
158
+ if typeName == "PdpHostOverviewDefaultSection":
159
+ data["host"]={
160
+ "id" : utils.get_nested_value(section,"sectionData.hostAvatar.loggingEventData.eventData.pdpContext.hostId",""),
161
+ "name": utils.get_nested_value(section,"sectionData.title",""),
162
+ }
163
+ elif typeName == "PdpOverviewV2Section":
164
+ data["sub_description"]["title"]=utils.get_nested_value(section,"sectionData.title","")
165
+ for item in utils.get_nested_value(section,"sectionData.overviewItems",[]):
166
+ data["sub_description"]["items"].append(utils.get_nested_value(item,"title",""))
167
+
168
+ for section in utils.get_nested_value(meta,"data.presentation.stayProductDetailPage.sections.sections",[]):
169
+ typeName=utils.get_nested_value(section,"section.__typename","")
170
+ match typeName:
171
+ case "HostProfileSection":
172
+ data["host"]["id"] = utils.get_nested_value(section,"section.hostAvatar.userID","")
173
+ data["host"]["name"] = utils.get_nested_value(section,"section.title","")
174
+ data["host"]["joined_on"] = utils.get_nested_value(section,"section.subtitle","")
175
+ data["host"]["description"] = utils.get_nested_value(section,"section.hostProfileDescription.htmlText","")
176
+ for cohost in utils.get_nested_value(section,"section.additionalHosts",[]):
177
+ data["co_hosts"].append({"id":cohost.get("id",""),"name":cohost.get("name","")})
178
+ case "PhotoTourModalSection":
179
+ for mediaItem in utils.get_nested_value(section,"section.mediaItems",[]):
180
+ img={
181
+ "title": mediaItem.get("accessibilityLabel",""),
182
+ "url": mediaItem.get("baseUrl",""),
183
+ }
184
+ data["images"].append(img)
185
+ case "PoliciesSection":
186
+ for houseRulesSection in utils.get_nested_value(section,"section.houseRulesSections",[]):
187
+ house_rule={
188
+ "title": houseRulesSection.get("title",""),
189
+ "values":[],
190
+ }
191
+ for item in houseRulesSection.get("items",[]):
192
+ if item.get("title","")=="Additional rules":
193
+ data["house_rules"]["aditional"]=utils.get_nested_value(item,"html.htmlText","")
194
+ continue
195
+ house_rule["values"].append({"title":item.get("title","") ,"icon": item.get("icon","")})
196
+
197
+ data["house_rules"]["general"].append(house_rule)
198
+ case "LocationSection":
199
+ for locationDetail in utils.get_nested_value(section,"section.seeAllLocationDetails",[]):
200
+ seeAllLocationDetail={
201
+ "title": locationDetail.get("title",""),
202
+ "content": utils.get_nested_value(locationDetail,"content.htmlText"),
203
+ }
204
+ data["location_descriptions"].append(seeAllLocationDetail)
205
+ case "PdpTitleSection":
206
+ data["title"]=section.get("title","")
207
+ case "PdpHighlightsSection":
208
+ for highlitingData in utils.get_nested_value(section,"section.highlights",[]):
209
+ highliting={
210
+ "title": highlitingData.get("title",""),
211
+ "subtitle": highlitingData.get("subtitle",""),
212
+ "icon": highlitingData.get("icon",""),
213
+ }
214
+ data["highlights"].append(highliting)
215
+ case "PdpDescriptionSection":
216
+ data["description"]= utils.get_nested_value(section,"section.htmlDescription.htmlText","")
217
+ case "AmenitiesSection":
218
+ for amenityGroupRaw in utils.get_nested_value(section,"section.seeAllAmenitiesGroups",[]):
219
+ amenityGroup={
220
+ "title": amenityGroupRaw.get("title",""),
221
+ "values": [],
222
+ }
223
+ for amenityRaw in amenityGroupRaw.get("amenities",[]):
224
+ amenity = {
225
+ "title": amenityRaw.get("title",""),
226
+ "subtitle": amenityRaw.get("subtitle",""),
227
+ "icon": amenityRaw.get("icon",""),
228
+ "available": amenityRaw.get("available",""),
229
+ }
230
+ amenityGroup["values"].append(amenity)
231
+ data["amenities"].append(amenityGroup)
232
+ return data
233
+
@@ -0,0 +1,112 @@
1
+
2
+ import pyairbnb.details as details
3
+ import pyairbnb.reviews as reviews
4
+ import pyairbnb.price as price
5
+ import pyairbnb.api as api
6
+ import pyairbnb.search as search
7
+ import pyairbnb.standardize as standardize
8
+ import pyairbnb.calendar as calendar
9
+ from datetime import datetime
10
+ from urllib.parse import urlparse, parse_qs
11
+
12
+ def search_all(check_in:str, check_out:str, ne_lat:float, ne_long:float, sw_lat:float, sw_long:float, zoom_value:int, currency:str, proxy_url:str):
13
+ api_key = api.get(proxy_url)
14
+ all_results = []
15
+ cursor = ""
16
+ while True:
17
+ results_raw = search.get(check_in,check_out,ne_lat,ne_long,sw_lat,sw_long,zoom_value,cursor, currency, api_key, proxy_url)
18
+ results = standardize.from_search(results_raw.get("searchResults",[]))
19
+ all_results = all_results + results
20
+ if len(results)==0 or "nextPageCursor" not in results_raw["paginationInfo"] or results_raw["paginationInfo"]["nextPageCursor"] is None:
21
+ break
22
+ cursor = results_raw["paginationInfo"]["nextPageCursor"]
23
+ return all_results
24
+
25
+ def search_first_page(check_in:str, check_out:str, ne_lat:float, ne_long:float, sw_lat:float, sw_long:float, zoom_value:int, cursor:str, currency:str, proxy_url:str):
26
+ api_key = api.get(proxy_url)
27
+ results = search.get(check_in,check_out,ne_lat,ne_long,sw_lat,sw_long,zoom_value,"", currency, api_key, proxy_url)
28
+ results = standardize.from_search(results)
29
+ return results
30
+
31
+ def get_reviews(room_url: str, proxy_url: str):
32
+ data, price_input, cookies = details.get(room_url, proxy_url)#in order not to waste data from this request, I return also this metadata
33
+ product_id = price_input["product_id"]
34
+ api_key = price_input["api_key"]
35
+ reviews_data = reviews.get(product_id,api_key,proxy_url)
36
+ data["reviews"] = reviews_data
37
+ return data
38
+
39
+ def get_calendar(room_url: str, proxy_url: str):
40
+ data, price_input, cookies = details.get(room_url, proxy_url)#in order not to waste data from this request, I return also this metadata
41
+ api_key = price_input["api_key"]
42
+
43
+ parsed_url = urlparse(room_url)
44
+ path = parsed_url.path
45
+ splited = path.split("/")
46
+ room_id = splited[len(splited)-1]
47
+
48
+ current_month = datetime.now().month
49
+ current_year = datetime.now().year
50
+ calendar_data = calendar.get(room_id,current_month,current_year,api_key,proxy_url)
51
+ data["calendar"] = calendar_data
52
+ return data
53
+
54
+ def get_details_from_url(room_url: str, currency: str, check_in: str, check_out: str, proxy_url: str):
55
+ data, price_input, cookies = details.get(room_url, proxy_url)
56
+ product_id = price_input["product_id"]
57
+ api_key = price_input["api_key"]
58
+
59
+ parsed_url = urlparse(room_url)
60
+ path = parsed_url.path
61
+ splited = path.split("/")
62
+ room_id = splited[len(splited)-1]
63
+
64
+ current_month = datetime.now().month
65
+ current_year = datetime.now().year
66
+ calendar_data = calendar.get(room_id,current_month,current_year,api_key,proxy_url)
67
+ data["calendar"] = calendar_data
68
+
69
+ reviews_data = reviews.get(product_id,api_key,proxy_url)
70
+ data["reviews"] = reviews_data
71
+ if check_in is None or check_in == "" or check_out is None or check_out == "":
72
+ return data
73
+ price_data = price.get(product_id,price_input["impression_id"],api_key,currency, cookies, check_in, check_out, proxy_url)
74
+ data["price"] = price_data
75
+ return data
76
+
77
+ def get_details_from_id(room_id: int, currency: str, check_in: str, check_out: str, proxy_url: str):
78
+ room_url = f"https://www.airbnb.com/rooms/{room_id}"
79
+ data, price_input, cookies = details.get(room_url, proxy_url)
80
+ product_id = price_input["product_id"]
81
+ api_key = price_input["api_key"]
82
+
83
+ current_month = datetime.now().month
84
+ current_year = datetime.now().year
85
+ calendar_data = calendar.get(room_id,current_month,current_year,api_key,proxy_url)
86
+ data["calendar"] = calendar_data
87
+
88
+ reviews_data = reviews.get(product_id,api_key,proxy_url)
89
+ data["reviews"] = reviews_data
90
+ if check_in is None or check_in == "" or check_out is None or check_out == "":
91
+ return data
92
+ price_data = price.get(product_id,price_input["impression_id"],api_key,currency, cookies, check_in, check_out, proxy_url)
93
+ data["price"] = price_data
94
+ return data
95
+
96
+
97
+ def get_details_from_id_and_domain(room_id: int, domain: str, currency: str, check_in: str, check_out: str, proxy_url: str):
98
+ room_url = f"https://{domain}/rooms/{room_id}"
99
+ data, price_input, cookies = details.get(room_url, proxy_url)
100
+ product_id = price_input["product_id"]
101
+ api_key = price_input["api_key"]
102
+ current_month = datetime.now().month
103
+ current_year = datetime.now().year
104
+ calendar_data = calendar.get(room_id,current_month,current_year,api_key,proxy_url)
105
+ data["calendar"] = calendar_data
106
+ reviews_data = reviews.get(product_id,api_key,proxy_url)
107
+ data["reviews"] = reviews_data
108
+ if check_in is None or check_in == "" or check_out is None or check_out == "":
109
+ return data
110
+ price_data = price.get(product_id,price_input["impression_id"],api_key,currency, cookies, check_in, check_out, proxy_url)
111
+ data["price"] = price_data
112
+ return data
@@ -0,0 +1,43 @@
1
+ import re
2
+ from urllib.parse import quote
3
+
4
+
5
+ regex_space = re.compile(r'[\s ]+')
6
+ regx_price = re.compile(r'\d+')
7
+
8
+ def remove_space(value:str):
9
+ return regex_space.sub(' ', value.strip())
10
+
11
+ def get_nested_value(dic, key_path, default=None):
12
+ keys = key_path.split(".")
13
+ current = dic
14
+ for key in keys:
15
+ current = current.get(key, {})
16
+ if current == {} or current is None:
17
+ return default
18
+ return current
19
+
20
+ def parse_price_symbol(price_raw: str):
21
+ price_raw = price_raw.replace(",", "")
22
+
23
+
24
+ price_number_match = regx_price.search(price_raw)
25
+
26
+ if price_number_match is None:
27
+ return 0,""
28
+
29
+ price_number = price_number_match.group(0)
30
+
31
+ price_currency = price_raw.replace(price_number, "").replace(" ", "").replace("-", "")
32
+
33
+ price_converted = float(price_number)
34
+ if price_raw.startswith("-"):
35
+ price_converted *= -1
36
+
37
+ return price_converted, price_currency
38
+
39
+ def parse_proxy(ip_or_domain: str,port: str, username: str, password: str) -> (str):
40
+ encoded_username = quote(username)
41
+ encoded_password = quote(password)
42
+ proxy_url = f"http://{encoded_username}:{encoded_password}@{ip_or_domain}:{port}"
43
+ return proxy_url
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyairbnb
3
+ Version: 0.0.0
4
+ Summary: Airbnb scraper in Python
5
+ Home-page: https://github.com/johnbalvin/pyairbnb
6
+ Author: John (John Balvin)
7
+ Author-email: John Balvin <johnchristian@hotmail.es>
8
+ Project-URL: Homepage, https://github.com/johnbalvin/pyairbnb
9
+ Keywords: airbnb,scraper,crawler,bot,reviews
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: curl_cffi
13
+ Requires-Dist: bs4
14
+ Requires-Dist: requests
15
+
16
+ # Airbnb scraper in Python
17
+
18
+ ## Overview
19
+ This project is an open-source tool developed in Python for extracting product information from Airbnb. It's designed to be easy to use, making it an ideal solution for developers looking for Airbnb product data.
20
+
21
+ ## Features
22
+ - Extract prices, available dates, reviews and others
23
+ - Full search support
24
+ - Extracts detailed product information from Airbnb
25
+ - Implemented in Python just because it's popular
26
+ - Easy to integrate with existing Python projects
27
+ - The code is optimize to work on this format: ```https://www.airbnb.com/rooms/[room_id]```
28
+
29
+ ## Important
30
+ - With the new airbnb changes, if you want to get the price from a room url you need to specify the date range
31
+ the date range should be on the format year-month-day, if you leave the date range empty, you will get the details but not the price
32
+
33
+
34
+ ### Install
35
+
36
+ ```bash
37
+ $ pip install pyairbnb
38
+ ```
39
+ ## Examples
40
+
41
+ ```Python
42
+ import pyairbnb
43
+ import json
44
+ currency="MXN"
45
+ check_in = "2025-02-01"
46
+ check_out = "2025-02-04"
47
+ ne_lat = -1.03866277790021
48
+ ne_long = -77.53091734683608
49
+ sw_lat = -1.1225978433925647
50
+ sw_long = -77.59713412765507
51
+ zoom_value = 2
52
+ search_results = pyairbnb.search_all(check_in,check_out,ne_lat,ne_long,sw_lat,sw_long,zoom_value, currency,"")
53
+ details_data = []
54
+ progress = 1
55
+ with open('search_results.json', 'w', encoding='utf-8') as f:
56
+ f.write(json.dumps(search_results))
57
+ for result in search_results[:10]:
58
+ data = pyairbnb.get_details_from_id(result["room_id"],currency,check_in,check_out,"")
59
+ details_data.append(data)
60
+ print("len results: ",progress, len(search_results))
61
+ progress=progress+1
62
+
63
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
64
+ f.write(json.dumps(details_data))
65
+ ```
66
+
67
+ ### Example for getting prices, avaiable dates, reviews and other metadata
68
+
69
+ ### Getting the reviews, along with metadata
70
+ ```Python
71
+ import pyairbnb
72
+ import json
73
+ room_url="https://www.airbnb.com/rooms/30931885"
74
+ data = pyairbnb.get_reviews(room_url,"")
75
+ with open('reviews.json', 'w', encoding='utf-8') as f:
76
+ f.write(json.dumps(data["reviews"]))
77
+ ```
78
+
79
+ ### Getting just the available/unavailable dates
80
+ ```Python
81
+ import pyairbnb
82
+ import json
83
+ room_url="https://www.airbnb.com/rooms/44590727"
84
+ calendar = pyairbnb.get_calendar(room_url,"")
85
+ with open('calendar.json', 'w', encoding='utf-8') as f:
86
+ f.write(json.dumps(calendar["calendar"]))
87
+ ```
88
+
89
+ ### if you want to get the price you need to send the check in and check out date(this is a requirement on airbn itself)
90
+ ```Python
91
+ import pyairbnb
92
+ import json
93
+ room_url="https://www.airbnb.com/rooms/43198150"
94
+ currency="USD"
95
+ check_in = "2025-01-02"
96
+ check_out = "2025-01-04"
97
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
98
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
99
+ f.write(json.dumps(data))
100
+ ```
101
+
102
+
103
+ ### example for getting details and NOT price
104
+ ### if you won't want the price, you can just leave it empty
105
+ ```Python
106
+ import pyairbnb
107
+ import json
108
+ room_url="https://www.airbnb.com/rooms/1029961446117217643"
109
+ currency="USD"
110
+ check_in = ""
111
+ check_out = ""
112
+ data = pyairbnb.get_details_from_url(room_url,currency,check_in,check_out,"")
113
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
114
+ f.write(json.dumps(data))
115
+ ```
116
+
117
+ ```Python
118
+ import pyairbnb
119
+ import json
120
+ room_id=18039593#the room id
121
+ currency="MXN"
122
+ check_in = ""
123
+ check_out = ""
124
+ proxy_url = pyairbnb.parse_proxy("[IP or domain]","[port]","[user name]","[password]")
125
+ data = pyairbnb.get_details_from_id(room_id,currency,check_in,check_out,proxy_url)
126
+ with open('details_data_json.json', 'w', encoding='utf-8') as f:
127
+ f.write(json.dumps(data))
128
+ ```
@@ -0,0 +1,20 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ src/pyairbnb/__init__.py
6
+ src/pyairbnb/api.py
7
+ src/pyairbnb/calendar.py
8
+ src/pyairbnb/details.py
9
+ src/pyairbnb/parse.py
10
+ src/pyairbnb/price.py
11
+ src/pyairbnb/reviews.py
12
+ src/pyairbnb/search.py
13
+ src/pyairbnb/standardize.py
14
+ src/pyairbnb/start.py
15
+ src/pyairbnb/utils.py
16
+ src/pyairbnb.egg-info/PKG-INFO
17
+ src/pyairbnb.egg-info/SOURCES.txt
18
+ src/pyairbnb.egg-info/dependency_links.txt
19
+ src/pyairbnb.egg-info/requires.txt
20
+ src/pyairbnb.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ curl_cffi
2
+ bs4
3
+ requests
@@ -0,0 +1 @@
1
+ pyairbnb