MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / add_scraper

Method add_scraper

botasaurus_server/botasaurus_server/server.py:138–246  ·  view source on GitHub ↗
(
        self,
        scraper_function,
        display_name=None,
        get_task_name=None,
        create_all_task=False,
        split_task=None,
        filters=[],
        sorts=[],
        views=[],
        remove_duplicates_by=None,
    )

Source from the content-addressed store, hash-verified

136 }
137
138 def add_scraper(
139 self,
140 scraper_function,
141 display_name=None,
142 get_task_name=None,
143 create_all_task=False,
144 split_task=None,
145 filters=[],
146 sorts=[],
147 views=[],
148 remove_duplicates_by=None,
149 ):
150 if not hasattr(scraper_function, "_scraper_type"):
151 raise ValueError(
152 "The function must be a scraping function decorated with either @browser, @request or @task."
153 )
154
155 if scraper_function._scraper_type not in [
156 ScraperType.REQUEST,
157 ScraperType.BROWSER,
158 ScraperType.TASK,
159 ]:
160 raise ValueError(
161 f"Invalid scraper type: {scraper_function._scraper_type}. Must be 'browser', 'request' or 'task'."
162 )
163
164 if create_all_task and not callable(split_task):
165 raise ValueError(
166 "split_task function must be provided when create_all_task is True."
167 )
168
169 if not isinstance(filters, list):
170 filters = [filters]
171
172
173 if not isinstance(sorts, list):
174 sorts = [sorts]
175
176
177 if not isinstance(views, list):
178 views = [views]
179
180 # if not create_all_task and remove_duplicates_by:
181 # raise ValueError(
182 # "create_all_task must be True when remove_duplicates_by is provided."
183 # )
184
185 # Check for duplicate views
186 view_ids = [view.id for view in views]
187 if len(view_ids) != len(set(view_ids)):
188 duplicate_view_ids = [id for id in view_ids if view_ids.count(id) > 1]
189 raise ValueError(f"Duplicate views found: {duplicate_view_ids}")
190
191
192
193 # Check for duplicate sorts
194 sort_ids = [sort.id for sort in sorts]
195 if len(sort_ids) != len(set(sort_ids)):

Callers

nothing calls this directly

Calls 2

get_input_jsMethod · 0.95
SortClass · 0.70

Tested by

no test coverage detected