pyairbnb 0.0.3__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.3/LICENSE +21 -0
- pyairbnb-0.0.3/PKG-INFO +219 -0
- pyairbnb-0.0.3/README.md +202 -0
- pyairbnb-0.0.3/pyproject.toml +15 -0
- pyairbnb-0.0.3/setup.cfg +4 -0
- pyairbnb-0.0.3/setup.py +17 -0
- pyairbnb-0.0.3/src/pyairbnb/__init__.py +7 -0
- pyairbnb-0.0.3/src/pyairbnb/api.py +35 -0
- pyairbnb-0.0.3/src/pyairbnb/calendarinfo.py +47 -0
- pyairbnb-0.0.3/src/pyairbnb/details.py +29 -0
- pyairbnb-0.0.3/src/pyairbnb/experience.py +92 -0
- pyairbnb-0.0.3/src/pyairbnb/host.py +64 -0
- pyairbnb-0.0.3/src/pyairbnb/host_details.py +56 -0
- pyairbnb-0.0.3/src/pyairbnb/parse.py +34 -0
- pyairbnb-0.0.3/src/pyairbnb/price.py +103 -0
- pyairbnb-0.0.3/src/pyairbnb/reviews.py +66 -0
- pyairbnb-0.0.3/src/pyairbnb/search.py +164 -0
- pyairbnb-0.0.3/src/pyairbnb/standardize.py +233 -0
- pyairbnb-0.0.3/src/pyairbnb/start.py +185 -0
- pyairbnb-0.0.3/src/pyairbnb/utils.py +43 -0
- pyairbnb-0.0.3/src/pyairbnb.egg-info/PKG-INFO +219 -0
- pyairbnb-0.0.3/src/pyairbnb.egg-info/SOURCES.txt +23 -0
- pyairbnb-0.0.3/src/pyairbnb.egg-info/dependency_links.txt +1 -0
- pyairbnb-0.0.3/src/pyairbnb.egg-info/requires.txt +3 -0
- pyairbnb-0.0.3/src/pyairbnb.egg-info/top_level.txt +1 -0
pyairbnb-0.0.3/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.
|
pyairbnb-0.0.3/PKG-INFO
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: pyairbnb
|
|
3
|
+
Version: 0.0.3
|
|
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
|
+
Dynamic: author
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
|
|
18
|
+
# Airbnb scraper in Python
|
|
19
|
+
|
|
20
|
+
## Overview
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
- Extract prices, available dates, reviews, host details and others
|
|
25
|
+
- Full search support
|
|
26
|
+
- Extracts detailed product information from Airbnb
|
|
27
|
+
- Implemented in Python just because it's popular
|
|
28
|
+
- Easy to integrate with existing Python projects
|
|
29
|
+
|
|
30
|
+
## Legacy
|
|
31
|
+
- This was a project first implemented on:[https://github.com/johnbalvin/pybnb](https://github.com/johnbalvin/pybnb) but was moved to [https://github.com/johnbalvin/pyairbnb](https://github.com/johnbalvin/pyairbnb)
|
|
32
|
+
to match the name with pip name
|
|
33
|
+
|
|
34
|
+
## Important
|
|
35
|
+
- With the new airbnb changes, if you want to get the price from a room url you need to specify the date range
|
|
36
|
+
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
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
$ pip install pyairbnb
|
|
43
|
+
```
|
|
44
|
+
## Examples
|
|
45
|
+
|
|
46
|
+
### Example for Searching Listings
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from pyairbnb.search import search_all
|
|
50
|
+
import json
|
|
51
|
+
|
|
52
|
+
# Define search parameters
|
|
53
|
+
currency = "MXN" # Currency for the search
|
|
54
|
+
check_in = "2025-02-01" # Check-in date
|
|
55
|
+
check_out = "2025-02-04" # Check-out date
|
|
56
|
+
ne_lat = -1.03866277790021 # North-East latitude
|
|
57
|
+
ne_long = -77.53091734683608 # North-East longitude
|
|
58
|
+
sw_lat = -1.1225978433925647 # South-West latitude
|
|
59
|
+
sw_long = -77.59713412765507 # South-West longitude
|
|
60
|
+
zoom_value = 2 # Zoom level for the map
|
|
61
|
+
|
|
62
|
+
# Search listings within specified coordinates and date range
|
|
63
|
+
search_results = search_all(check_in, check_out, ne_lat, ne_long, sw_lat, sw_long, zoom_value, currency, "")
|
|
64
|
+
|
|
65
|
+
# Save the search results as a JSON file
|
|
66
|
+
with open('search_results.json', 'w', encoding='utf-8') as f:
|
|
67
|
+
f.write(json.dumps(search_results)) # Convert results to JSON and write to file
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Retrieving Details for Listings
|
|
71
|
+
#### Retrieve Prices, Availability, Reviews, and Host Information
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import pyairbnb
|
|
75
|
+
import json
|
|
76
|
+
room_url="https://www.airbnb.com/rooms/30931885"
|
|
77
|
+
data = pyairbnb.get_reviews(room_url,"")
|
|
78
|
+
with open('reviews.json', 'w', encoding='utf-8') as f:
|
|
79
|
+
f.write(json.dumps(data["reviews"]))
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Getting listings from user id
|
|
83
|
+
```Python
|
|
84
|
+
import pyairbnb
|
|
85
|
+
import json
|
|
86
|
+
host_id = 0
|
|
87
|
+
api_key = pyairbnb.get_api_key("")
|
|
88
|
+
listings = pyairbnb.get_listings_from_user(host_id,api_key,"")
|
|
89
|
+
with open('listings.json', 'w', encoding='utf-8') as f:
|
|
90
|
+
f.write(json.dumps(listings))
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Getting experiences by just taking the first autocompletions that you would normally do manually on the website
|
|
94
|
+
```Python
|
|
95
|
+
import pyairbnb
|
|
96
|
+
import json
|
|
97
|
+
check_in = "2025-04-10"
|
|
98
|
+
check_out = "2025-04-12"
|
|
99
|
+
currency = "EUR"
|
|
100
|
+
user_input_text = "Estados Unidos"
|
|
101
|
+
locale = "es"
|
|
102
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
103
|
+
api_key = pyairbnb.get_api_key("")
|
|
104
|
+
experiences = pyairbnb.experience_search(user_input_text, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
105
|
+
with open('experiences.json', 'w', encoding='utf-8') as f:
|
|
106
|
+
f.write(json.dumps(experiences))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Getting experiences by first getting the autocompletions
|
|
110
|
+
```Python
|
|
111
|
+
import pyairbnb
|
|
112
|
+
import json
|
|
113
|
+
check_in = "2025-03-06"
|
|
114
|
+
check_out = "2025-03-10"
|
|
115
|
+
currency = "USD"
|
|
116
|
+
user_input_text = "cuenca"
|
|
117
|
+
locale = "pt"
|
|
118
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
119
|
+
api_key = pyairbnb.get_api_key("")
|
|
120
|
+
markets_data = pyairbnb.search.get_markets(currency,locale,api_key,proxy_url)
|
|
121
|
+
markets = pyairbnb.get_nested_value(markets_data,"user_markets", [])
|
|
122
|
+
if len(markets)==0:
|
|
123
|
+
raise Exception("markets are empty")
|
|
124
|
+
config_token = pyairbnb.get_nested_value(markets[0],"satori_parameters", "")
|
|
125
|
+
country_code = pyairbnb.get_nested_value(markets[0],"country_code", "")
|
|
126
|
+
if config_token=="" or country_code=="":
|
|
127
|
+
raise Exception("config_token or country_code are empty")
|
|
128
|
+
place_ids_results = pyairbnb.get_places_ids(country_code, user_input_text, currency, locale, config_token, api_key, proxy_url)
|
|
129
|
+
if len(place_ids_results)==0:
|
|
130
|
+
raise Exception("empty places ids")
|
|
131
|
+
place_id = pyairbnb.get_nested_value(place_ids_results[0],"location.google_place_id", "")
|
|
132
|
+
location_name = pyairbnb.get_nested_value(place_ids_results[0],"location.location_name", "")
|
|
133
|
+
if place_id=="" or location_name=="":
|
|
134
|
+
raise Exception("place_id or location_name are empty")
|
|
135
|
+
[result,cursor] = pyairbnb.experience_search_by_place_id("", place_id, location_name, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
136
|
+
while cursor!="":
|
|
137
|
+
[result_tmp,cursor] = pyairbnb.experience_search_by_place_id(cursor, place_id, location_name, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
138
|
+
if len(result_tmp)==0:
|
|
139
|
+
break
|
|
140
|
+
result = result + result_tmp
|
|
141
|
+
with open('experiences.json', 'w', encoding='utf-8') as f:
|
|
142
|
+
f.write(json.dumps(result))
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Getting available/unavailable homes along with metadata
|
|
146
|
+
```Python
|
|
147
|
+
import pyairbnb
|
|
148
|
+
import json
|
|
149
|
+
|
|
150
|
+
# Define listing URL and parameters
|
|
151
|
+
room_url = "https://www.airbnb.com/rooms/1029961446117217643" # Listing URL
|
|
152
|
+
currency = "USD" # Currency for the listing details
|
|
153
|
+
|
|
154
|
+
# Retrieve listing details without including the price information (no check-in/check-out dates)
|
|
155
|
+
data = pyairbnb.get_details(room_url=room_url, currency=currency)
|
|
156
|
+
|
|
157
|
+
# Save the retrieved details to a JSON file
|
|
158
|
+
with open('details_data.json', 'w', encoding='utf-8') as f:
|
|
159
|
+
f.write(json.dumps(data)) # Convert the data to JSON and save it
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Retrieve Details Using Room ID with Proxy
|
|
163
|
+
You can also use `get_details` with a room ID and an optional proxy.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
import pyairbnb
|
|
167
|
+
from urllib.parse import urlparse
|
|
168
|
+
import json
|
|
169
|
+
|
|
170
|
+
# Define listing parameters
|
|
171
|
+
room_id = 18039593 # Listing room ID
|
|
172
|
+
currency = "MXN" # Currency for the listing details
|
|
173
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
174
|
+
|
|
175
|
+
# Retrieve listing details by room ID with a proxy
|
|
176
|
+
data = get_details(room_id=room_id, currency=currency, proxy_url=proxy_url)
|
|
177
|
+
|
|
178
|
+
# Save the retrieved details to a JSON file
|
|
179
|
+
with open('details_data.json', 'w', encoding='utf-8') as f:
|
|
180
|
+
f.write(json.dumps(data)) # Convert the data to JSON and save it
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Retrieve Reviews for a Listing
|
|
184
|
+
Use `get_reviews` to extract reviews and metadata for a specific listing.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
import pyairbnb
|
|
188
|
+
import json
|
|
189
|
+
|
|
190
|
+
# Define listing URL and proxy URL
|
|
191
|
+
room_url = "https://www.airbnb.com/rooms/30931885" # Listing URL
|
|
192
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
193
|
+
|
|
194
|
+
# Retrieve reviews for the specified listing
|
|
195
|
+
reviews_data = pyairbnb.get_reviews(room_url, proxy_url)
|
|
196
|
+
|
|
197
|
+
# Save the reviews data to a JSON file
|
|
198
|
+
with open('reviews.json', 'w', encoding='utf-8') as f:
|
|
199
|
+
f.write(json.dumps(reviews_data["reviews"])) # Extract reviews and save them to a file
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Retrieve Availability for a Listing
|
|
203
|
+
The `get_calendar` function provides availability information for specified listings.
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
import pyairbnb
|
|
207
|
+
import json
|
|
208
|
+
|
|
209
|
+
# Define listing parameters
|
|
210
|
+
room_id = "44590727" # Listing room ID
|
|
211
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
212
|
+
|
|
213
|
+
# Retrieve availability for the specified listing
|
|
214
|
+
calendar_data = pyairbnb.get_calendar(room_id, "", proxy_url)
|
|
215
|
+
|
|
216
|
+
# Save the calendar data (availability) to a JSON file
|
|
217
|
+
with open('calendar.json', 'w', encoding='utf-8') as f:
|
|
218
|
+
f.write(json.dumps(calendar_data["calendar"])) # Extract calendar data and save it to a file
|
|
219
|
+
```
|
pyairbnb-0.0.3/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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, host details 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
|
+
|
|
13
|
+
## Legacy
|
|
14
|
+
- This was a project first implemented on:[https://github.com/johnbalvin/pybnb](https://github.com/johnbalvin/pybnb) but was moved to [https://github.com/johnbalvin/pyairbnb](https://github.com/johnbalvin/pyairbnb)
|
|
15
|
+
to match the name with pip name
|
|
16
|
+
|
|
17
|
+
## Important
|
|
18
|
+
- With the new airbnb changes, if you want to get the price from a room url you need to specify the date range
|
|
19
|
+
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
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$ pip install pyairbnb
|
|
26
|
+
```
|
|
27
|
+
## Examples
|
|
28
|
+
|
|
29
|
+
### Example for Searching Listings
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from pyairbnb.search import search_all
|
|
33
|
+
import json
|
|
34
|
+
|
|
35
|
+
# Define search parameters
|
|
36
|
+
currency = "MXN" # Currency for the search
|
|
37
|
+
check_in = "2025-02-01" # Check-in date
|
|
38
|
+
check_out = "2025-02-04" # Check-out date
|
|
39
|
+
ne_lat = -1.03866277790021 # North-East latitude
|
|
40
|
+
ne_long = -77.53091734683608 # North-East longitude
|
|
41
|
+
sw_lat = -1.1225978433925647 # South-West latitude
|
|
42
|
+
sw_long = -77.59713412765507 # South-West longitude
|
|
43
|
+
zoom_value = 2 # Zoom level for the map
|
|
44
|
+
|
|
45
|
+
# Search listings within specified coordinates and date range
|
|
46
|
+
search_results = search_all(check_in, check_out, ne_lat, ne_long, sw_lat, sw_long, zoom_value, currency, "")
|
|
47
|
+
|
|
48
|
+
# Save the search results as a JSON file
|
|
49
|
+
with open('search_results.json', 'w', encoding='utf-8') as f:
|
|
50
|
+
f.write(json.dumps(search_results)) # Convert results to JSON and write to file
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Retrieving Details for Listings
|
|
54
|
+
#### Retrieve Prices, Availability, Reviews, and Host Information
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import pyairbnb
|
|
58
|
+
import json
|
|
59
|
+
room_url="https://www.airbnb.com/rooms/30931885"
|
|
60
|
+
data = pyairbnb.get_reviews(room_url,"")
|
|
61
|
+
with open('reviews.json', 'w', encoding='utf-8') as f:
|
|
62
|
+
f.write(json.dumps(data["reviews"]))
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Getting listings from user id
|
|
66
|
+
```Python
|
|
67
|
+
import pyairbnb
|
|
68
|
+
import json
|
|
69
|
+
host_id = 0
|
|
70
|
+
api_key = pyairbnb.get_api_key("")
|
|
71
|
+
listings = pyairbnb.get_listings_from_user(host_id,api_key,"")
|
|
72
|
+
with open('listings.json', 'w', encoding='utf-8') as f:
|
|
73
|
+
f.write(json.dumps(listings))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Getting experiences by just taking the first autocompletions that you would normally do manually on the website
|
|
77
|
+
```Python
|
|
78
|
+
import pyairbnb
|
|
79
|
+
import json
|
|
80
|
+
check_in = "2025-04-10"
|
|
81
|
+
check_out = "2025-04-12"
|
|
82
|
+
currency = "EUR"
|
|
83
|
+
user_input_text = "Estados Unidos"
|
|
84
|
+
locale = "es"
|
|
85
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
86
|
+
api_key = pyairbnb.get_api_key("")
|
|
87
|
+
experiences = pyairbnb.experience_search(user_input_text, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
88
|
+
with open('experiences.json', 'w', encoding='utf-8') as f:
|
|
89
|
+
f.write(json.dumps(experiences))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Getting experiences by first getting the autocompletions
|
|
93
|
+
```Python
|
|
94
|
+
import pyairbnb
|
|
95
|
+
import json
|
|
96
|
+
check_in = "2025-03-06"
|
|
97
|
+
check_out = "2025-03-10"
|
|
98
|
+
currency = "USD"
|
|
99
|
+
user_input_text = "cuenca"
|
|
100
|
+
locale = "pt"
|
|
101
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
102
|
+
api_key = pyairbnb.get_api_key("")
|
|
103
|
+
markets_data = pyairbnb.search.get_markets(currency,locale,api_key,proxy_url)
|
|
104
|
+
markets = pyairbnb.get_nested_value(markets_data,"user_markets", [])
|
|
105
|
+
if len(markets)==0:
|
|
106
|
+
raise Exception("markets are empty")
|
|
107
|
+
config_token = pyairbnb.get_nested_value(markets[0],"satori_parameters", "")
|
|
108
|
+
country_code = pyairbnb.get_nested_value(markets[0],"country_code", "")
|
|
109
|
+
if config_token=="" or country_code=="":
|
|
110
|
+
raise Exception("config_token or country_code are empty")
|
|
111
|
+
place_ids_results = pyairbnb.get_places_ids(country_code, user_input_text, currency, locale, config_token, api_key, proxy_url)
|
|
112
|
+
if len(place_ids_results)==0:
|
|
113
|
+
raise Exception("empty places ids")
|
|
114
|
+
place_id = pyairbnb.get_nested_value(place_ids_results[0],"location.google_place_id", "")
|
|
115
|
+
location_name = pyairbnb.get_nested_value(place_ids_results[0],"location.location_name", "")
|
|
116
|
+
if place_id=="" or location_name=="":
|
|
117
|
+
raise Exception("place_id or location_name are empty")
|
|
118
|
+
[result,cursor] = pyairbnb.experience_search_by_place_id("", place_id, location_name, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
119
|
+
while cursor!="":
|
|
120
|
+
[result_tmp,cursor] = pyairbnb.experience_search_by_place_id(cursor, place_id, location_name, currency, locale, check_in, check_out, api_key, proxy_url)
|
|
121
|
+
if len(result_tmp)==0:
|
|
122
|
+
break
|
|
123
|
+
result = result + result_tmp
|
|
124
|
+
with open('experiences.json', 'w', encoding='utf-8') as f:
|
|
125
|
+
f.write(json.dumps(result))
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Getting available/unavailable homes along with metadata
|
|
129
|
+
```Python
|
|
130
|
+
import pyairbnb
|
|
131
|
+
import json
|
|
132
|
+
|
|
133
|
+
# Define listing URL and parameters
|
|
134
|
+
room_url = "https://www.airbnb.com/rooms/1029961446117217643" # Listing URL
|
|
135
|
+
currency = "USD" # Currency for the listing details
|
|
136
|
+
|
|
137
|
+
# Retrieve listing details without including the price information (no check-in/check-out dates)
|
|
138
|
+
data = pyairbnb.get_details(room_url=room_url, currency=currency)
|
|
139
|
+
|
|
140
|
+
# Save the retrieved details to a JSON file
|
|
141
|
+
with open('details_data.json', 'w', encoding='utf-8') as f:
|
|
142
|
+
f.write(json.dumps(data)) # Convert the data to JSON and save it
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Retrieve Details Using Room ID with Proxy
|
|
146
|
+
You can also use `get_details` with a room ID and an optional proxy.
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import pyairbnb
|
|
150
|
+
from urllib.parse import urlparse
|
|
151
|
+
import json
|
|
152
|
+
|
|
153
|
+
# Define listing parameters
|
|
154
|
+
room_id = 18039593 # Listing room ID
|
|
155
|
+
currency = "MXN" # Currency for the listing details
|
|
156
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
157
|
+
|
|
158
|
+
# Retrieve listing details by room ID with a proxy
|
|
159
|
+
data = get_details(room_id=room_id, currency=currency, proxy_url=proxy_url)
|
|
160
|
+
|
|
161
|
+
# Save the retrieved details to a JSON file
|
|
162
|
+
with open('details_data.json', 'w', encoding='utf-8') as f:
|
|
163
|
+
f.write(json.dumps(data)) # Convert the data to JSON and save it
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Retrieve Reviews for a Listing
|
|
167
|
+
Use `get_reviews` to extract reviews and metadata for a specific listing.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import pyairbnb
|
|
171
|
+
import json
|
|
172
|
+
|
|
173
|
+
# Define listing URL and proxy URL
|
|
174
|
+
room_url = "https://www.airbnb.com/rooms/30931885" # Listing URL
|
|
175
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
176
|
+
|
|
177
|
+
# Retrieve reviews for the specified listing
|
|
178
|
+
reviews_data = pyairbnb.get_reviews(room_url, proxy_url)
|
|
179
|
+
|
|
180
|
+
# Save the reviews data to a JSON file
|
|
181
|
+
with open('reviews.json', 'w', encoding='utf-8') as f:
|
|
182
|
+
f.write(json.dumps(reviews_data["reviews"])) # Extract reviews and save them to a file
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Retrieve Availability for a Listing
|
|
186
|
+
The `get_calendar` function provides availability information for specified listings.
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import pyairbnb
|
|
190
|
+
import json
|
|
191
|
+
|
|
192
|
+
# Define listing parameters
|
|
193
|
+
room_id = "44590727" # Listing room ID
|
|
194
|
+
proxy_url = "" # Proxy URL (if needed)
|
|
195
|
+
|
|
196
|
+
# Retrieve availability for the specified listing
|
|
197
|
+
calendar_data = pyairbnb.get_calendar(room_id, "", proxy_url)
|
|
198
|
+
|
|
199
|
+
# Save the calendar data (availability) to a JSON file
|
|
200
|
+
with open('calendar.json', 'w', encoding='utf-8') as f:
|
|
201
|
+
f.write(json.dumps(calendar_data["calendar"])) # Extract calendar data and save it to a file
|
|
202
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
|
|
3
|
+
version = '0.0.3'
|
|
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'
|
pyairbnb-0.0.3/setup.cfg
ADDED
pyairbnb-0.0.3/setup.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
VERSION = '0.0.3'
|
|
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,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
|
|
@@ -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
|