yad2-scraper 0.5.2__tar.gz → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yad2-scraper
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: Scrape Yad2 in Python.
5
5
  License: LICENSE
6
6
  Author: dav ost
@@ -59,9 +59,9 @@ To fetch any category, use the `fetch_category` function:
59
59
  from yad2_scraper import fetch_category, Yad2Category
60
60
 
61
61
  # Fetch real estate category (returns a generic Yad2Category object)
62
- real_estate_category_page1 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=1)
62
+ real_estate_page1 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=1)
63
63
  ...
64
- real_estate_category_page2 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=2)
64
+ real_estate_page2 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=2)
65
65
  ...
66
66
  ```
67
67
 
@@ -75,21 +75,21 @@ from yad2_scraper import fetch_vehicle_category, OrderVehiclesBy, Field
75
75
  # Fetch cars category
76
76
  cars_category = fetch_vehicle_category("cars")
77
77
 
78
- for car_data in cars_category.load_next_data().iterate_vehicles():
78
+ for car_data in cars_category.load_next_data().get_data():
79
79
  print(car_data.model(Field.ENGLISH_TEXT))
80
80
  print(car_data.test_date)
81
81
  print(car_data.price)
82
82
  ...
83
83
 
84
84
  # Fetch motorcycles category
85
- motorcycle_categories = fetch_vehicle_category(
85
+ motorcycle_category = fetch_vehicle_category(
86
86
  "motorcycles",
87
87
  price_range=(5000, 15000),
88
88
  year_range=(2010, 2020),
89
89
  order_by=OrderVehiclesBy.PRICE_LOWEST_TO_HIGHEST
90
90
  )
91
91
 
92
- for motorcycle_tag in motorcycle_categories.get_vehicle_tags():
92
+ for motorcycle_tag in motorcycle_category.get_tags():
93
93
  print(motorcycle_tag.page_link)
94
94
  print(motorcycle_tag.hand)
95
95
  print(motorcycle_tag.price)
@@ -129,22 +129,23 @@ from yad2_scraper.vehicles import (
129
129
  get_vehicle_category_url
130
130
  )
131
131
 
132
- # Fetch businesses for sale category with filters
133
- scraper = Yad2Scraper()
132
+ scraper = Yad2Scraper(request_defaults={"timeout": 5}, max_request_attempts=3)
133
+
134
+ # Fetch businesses-for-sale category with filters
134
135
  url = "https://www.yad2.co.il/products/businesses-for-sale"
135
136
  query_filters = QueryFilters(price_range=(10000, 250000), order_by=OrderBy.PRICE_LOWEST_TO_HIGHEST)
136
- business_for_sale_category = scraper.fetch_category(url, Yad2Category, params=query_filters)
137
+ businesses_for_sale_category = scraper.fetch_category(url, Yad2Category, params=query_filters)
137
138
 
138
- # Fetch watercraft (vehicle) category with filters
139
+ # Fetch watercraft category with filters
139
140
  url = get_vehicle_category_url("watercraft")
140
141
  query_filters = VehiclesQueryFilters(year_range=(2010, 2020), order_by=OrderVehiclesBy.DATE)
141
142
  watercraft_category = scraper.fetch_category(url, Yad2VehiclesCategory, params=query_filters)
142
143
  ```
143
144
 
144
- #### Attributes & Methods
145
+ #### Features & Functionality
145
146
 
146
- The `Yad2Scraper` object contains a lot of additional attributes & methods which you can use.
147
- Please check out the actual code documentation for more details.
147
+ The `Yad2Scraper` class provides various attributes and methods to customize and extend its functionality.
148
+ For detailed usage and examples, refer to the code documentation.
148
149
 
149
150
  ## Contributing
150
151
 
@@ -36,9 +36,9 @@ To fetch any category, use the `fetch_category` function:
36
36
  from yad2_scraper import fetch_category, Yad2Category
37
37
 
38
38
  # Fetch real estate category (returns a generic Yad2Category object)
39
- real_estate_category_page1 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=1)
39
+ real_estate_page1 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=1)
40
40
  ...
41
- real_estate_category_page2 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=2)
41
+ real_estate_page2 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=2)
42
42
  ...
43
43
  ```
44
44
 
@@ -52,21 +52,21 @@ from yad2_scraper import fetch_vehicle_category, OrderVehiclesBy, Field
52
52
  # Fetch cars category
53
53
  cars_category = fetch_vehicle_category("cars")
54
54
 
55
- for car_data in cars_category.load_next_data().iterate_vehicles():
55
+ for car_data in cars_category.load_next_data().get_data():
56
56
  print(car_data.model(Field.ENGLISH_TEXT))
57
57
  print(car_data.test_date)
58
58
  print(car_data.price)
59
59
  ...
60
60
 
61
61
  # Fetch motorcycles category
62
- motorcycle_categories = fetch_vehicle_category(
62
+ motorcycle_category = fetch_vehicle_category(
63
63
  "motorcycles",
64
64
  price_range=(5000, 15000),
65
65
  year_range=(2010, 2020),
66
66
  order_by=OrderVehiclesBy.PRICE_LOWEST_TO_HIGHEST
67
67
  )
68
68
 
69
- for motorcycle_tag in motorcycle_categories.get_vehicle_tags():
69
+ for motorcycle_tag in motorcycle_category.get_tags():
70
70
  print(motorcycle_tag.page_link)
71
71
  print(motorcycle_tag.hand)
72
72
  print(motorcycle_tag.price)
@@ -106,22 +106,23 @@ from yad2_scraper.vehicles import (
106
106
  get_vehicle_category_url
107
107
  )
108
108
 
109
- # Fetch businesses for sale category with filters
110
- scraper = Yad2Scraper()
109
+ scraper = Yad2Scraper(request_defaults={"timeout": 5}, max_request_attempts=3)
110
+
111
+ # Fetch businesses-for-sale category with filters
111
112
  url = "https://www.yad2.co.il/products/businesses-for-sale"
112
113
  query_filters = QueryFilters(price_range=(10000, 250000), order_by=OrderBy.PRICE_LOWEST_TO_HIGHEST)
113
- business_for_sale_category = scraper.fetch_category(url, Yad2Category, params=query_filters)
114
+ businesses_for_sale_category = scraper.fetch_category(url, Yad2Category, params=query_filters)
114
115
 
115
- # Fetch watercraft (vehicle) category with filters
116
+ # Fetch watercraft category with filters
116
117
  url = get_vehicle_category_url("watercraft")
117
118
  query_filters = VehiclesQueryFilters(year_range=(2010, 2020), order_by=OrderVehiclesBy.DATE)
118
119
  watercraft_category = scraper.fetch_category(url, Yad2VehiclesCategory, params=query_filters)
119
120
  ```
120
121
 
121
- #### Attributes & Methods
122
+ #### Features & Functionality
122
123
 
123
- The `Yad2Scraper` object contains a lot of additional attributes & methods which you can use.
124
- Please check out the actual code documentation for more details.
124
+ The `Yad2Scraper` class provides various attributes and methods to customize and extend its functionality.
125
+ For detailed usage and examples, refer to the code documentation.
125
126
 
126
127
  ## Contributing
127
128
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "yad2-scraper"
3
- version = "0.5.2"
3
+ version = "0.5.3"
4
4
  description = "Scrape Yad2 in Python."
5
5
  authors = ["dav ost <davidost2003@gmail.com>"]
6
6
  license = "LICENSE"
@@ -7,8 +7,9 @@ from yad2_scraper.vehicles.next_data import VehiclesNextData
7
7
 
8
8
  class Yad2VehiclesCategory(Yad2Category):
9
9
  """Represents a Yad2 vehicles category parsed from an HTML page."""
10
- def get_vehicle_tags(self) -> List[VehicleTag]:
11
- """Retrieve a and return list of vehicle tags from the current category."""
10
+
11
+ def get_tags(self) -> List[VehicleTag]:
12
+ """Retrieve and return a list of tags from the current vehicle page."""
12
13
  tags = self.find_all_tags_by_class_substring("div", "feedItemBox")
13
14
  return [VehicleTag(tag) for tag in tags]
14
15
 
@@ -307,8 +307,10 @@ class VehicleData(metaclass=SafeAccessOptionalKeysMeta):
307
307
  class VehiclesNextData(NextData):
308
308
  """Represents structured Next.js data of a specific vehicle category."""
309
309
 
310
- def iterate_vehicles(self) -> Iterator[VehicleData]:
311
- """Iterates through the queries and yields `VehicleData` objects."""
310
+ def get_data(self) -> List[VehicleData]:
311
+ """Extract and return a list of vehicle-data objects from the stored queries."""
312
+ data_list = []
313
+
312
314
  for query in self.queries:
313
315
  data = query["state"].get("data")
314
316
 
@@ -317,4 +319,6 @@ class VehiclesNextData(NextData):
317
319
 
318
320
  for vehicle_data in itertools.chain.from_iterable(data.values()):
319
321
  if isinstance(vehicle_data, dict):
320
- yield VehicleData(vehicle_data)
322
+ data_list.append(VehicleData(vehicle_data))
323
+
324
+ return data_list
File without changes