@@ -79,16 +79,10 @@ def crawl(
7979 client , job_name , site , max_to_crawl , max_to_process , hops , restrict_domain ,
8080 api_url , crawl_delay , url_crawl_pattern , url_process_pattern ,
8181 obey_robots , use_proxies , custom_headers ,
82- {
83- "urlCrawlRegEx" : url_crawl_regex ,
84- "urlProcessRegEx" : url_process_regex ,
85- "pageProcessPattern" : page_process_pattern ,
86- "maxToCrawlPerSubdomain" : max_to_crawl_per_subdomain ,
87- "maxToProcessPerSubdomain" : max_to_process_per_subdomain ,
88- "useCanonical" : None if use_canonical is None else int (use_canonical ),
89- "notifyWebhook" : notify_webhook ,
90- "notifyEmail" : notify_email ,
91- },
82+ _named_create_options (
83+ url_crawl_regex , url_process_regex , page_process_pattern , max_to_crawl_per_subdomain ,
84+ max_to_process_per_subdomain , use_canonical , notify_webhook , notify_email ,
85+ ),
9286 )
9387 _raise_on_create_error (client .request ("GET" , client .crawler_url , params = params ))
9488
@@ -142,6 +136,29 @@ def _raise_on_create_error(response: Any) -> None:
142136 raise APIError (response .status_code , response .text , headers = dict (response .headers ))
143137
144138
139+ def _named_create_options (
140+ url_crawl_regex : Optional [str ],
141+ url_process_regex : Optional [str ],
142+ page_process_pattern : Optional [str ],
143+ max_to_crawl_per_subdomain : Optional [int ],
144+ max_to_process_per_subdomain : Optional [int ],
145+ use_canonical : Optional [bool ],
146+ notify_webhook : Optional [str ],
147+ notify_email : Optional [str ],
148+ ) -> Dict [str , Any ]:
149+ """Python names -> wire names for the S2 create options; ``None`` means "not set"."""
150+ return {
151+ "urlCrawlRegEx" : url_crawl_regex ,
152+ "urlProcessRegEx" : url_process_regex ,
153+ "pageProcessPattern" : page_process_pattern ,
154+ "maxToCrawlPerSubdomain" : max_to_crawl_per_subdomain ,
155+ "maxToProcessPerSubdomain" : max_to_process_per_subdomain ,
156+ "useCanonical" : None if use_canonical is None else int (use_canonical ),
157+ "notifyWebhook" : notify_webhook ,
158+ "notifyEmail" : notify_email ,
159+ }
160+
161+
145162def _build_crawl_params (client : Any , job_name : str , site : str , max_to_crawl : int ,
146163 max_to_process : int , hops : int , restrict_domain : bool ,
147164 api_url : str , crawl_delay : float , url_crawl_pattern : Optional [str ],
@@ -228,16 +245,10 @@ async def crawl_async(
228245 client , job_name , site , max_to_crawl , max_to_process , hops , restrict_domain ,
229246 api_url , crawl_delay , url_crawl_pattern , url_process_pattern ,
230247 obey_robots , use_proxies , custom_headers ,
231- {
232- "urlCrawlRegEx" : url_crawl_regex ,
233- "urlProcessRegEx" : url_process_regex ,
234- "pageProcessPattern" : page_process_pattern ,
235- "maxToCrawlPerSubdomain" : max_to_crawl_per_subdomain ,
236- "maxToProcessPerSubdomain" : max_to_process_per_subdomain ,
237- "useCanonical" : None if use_canonical is None else int (use_canonical ),
238- "notifyWebhook" : notify_webhook ,
239- "notifyEmail" : notify_email ,
240- },
248+ _named_create_options (
249+ url_crawl_regex , url_process_regex , page_process_pattern , max_to_crawl_per_subdomain ,
250+ max_to_process_per_subdomain , use_canonical , notify_webhook , notify_email ,
251+ ),
241252 )
242253 _raise_on_create_error (await client .request ("GET" , client .crawler_url , params = params ))
243254
0 commit comments