fix(HandelsRegister): Refined HandelsRegister functionality for better error handling and response capture.
This commit is contained in:
		| @@ -1,5 +1,12 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## 2025-01-03 - 1.3.1 - fix(HandelsRegister) | ||||
| Refined HandelsRegister functionality for better error handling and response capture. | ||||
|  | ||||
| - Improved parsing logic in parseGermanRegistration function. | ||||
| - Enhanced navigateToPage and clickFindButton methods with error messages for clarity. | ||||
| - Implemented a new responseListener to handle and log HTTP responses correctly. | ||||
|  | ||||
| ## 2025-01-03 - 1.3.0 - feat(core) | ||||
| Enhanced data handling capabilities and improved company search functionalities. | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,6 @@ | ||||
|  */ | ||||
| export const commitinfo = { | ||||
|   name: '@fin.cx/opendata', | ||||
|   version: '1.3.0', | ||||
|   version: '1.3.1', | ||||
|   description: 'A TypeScript library for accessing, managing, and updating open business data, focused on German companies and integrating with MongoDB.' | ||||
| } | ||||
|   | ||||
| @@ -114,7 +114,8 @@ export class HandelsRegister { | ||||
|   private async parseGermanRegistration( | ||||
|     input: string | ||||
|   ): Promise<BusinessRecord['data']['germanParsedRegistration']> { | ||||
|     const regex = /District court (\p{L}[\p{L}\s-]*?(?:\s*\([\p{L}\s-]+\))?)\s+(HRA|HRB|GnR|VR|PR|GsR)\s+(\d+)/u; | ||||
|     const regex = | ||||
|       /District court (\p{L}[\p{L}\s-]*?(?:\s*\([\p{L}\s-]+\))?)\s+(HRA|HRB|GnR|VR|PR|GsR)\s+(\d+)/u; | ||||
|     const match = input.match(regex); | ||||
|  | ||||
|     if (match) { | ||||
| @@ -227,5 +228,67 @@ await page.evaluate((court) => { | ||||
|  | ||||
|     const businessRecords = await this.waitForResults(page); | ||||
|     console.log(businessRecords); | ||||
|  | ||||
|     // Define the response listener | ||||
|     const responseListener = async ( | ||||
|       response: plugins.smartbrowser.smartpuppeteer.puppeteer.HTTPResponse | ||||
|     ) => { | ||||
|       // Ignore preflight (OPTIONS) requests | ||||
|       if (response.request().method() === 'OPTIONS') { | ||||
|         console.log(`Ignoring preflight request: ${response.url()}`); | ||||
|         return; | ||||
|       } | ||||
|  | ||||
|       // Check for downloads (Content-Disposition header) | ||||
|       const contentDisposition = response.headers()['content-disposition']; | ||||
|  | ||||
|       if (contentDisposition && contentDisposition.includes('attachment')) { | ||||
|         console.log(`Download detected: ${response.url()}`); | ||||
|         try { | ||||
|           const buffer = await response.buffer(); | ||||
|           console.log(`Downloaded file size: ${buffer.length} bytes`); | ||||
|         } catch (error) { | ||||
|           console.error('Error downloading file:', error); | ||||
|         } | ||||
|       } | ||||
|     }; | ||||
|     page.on('response', responseListener); | ||||
|  | ||||
|     // Click the element | ||||
|     await page.evaluate(() => { | ||||
|       // Locate the table body | ||||
|       const tableBody = document.querySelector( | ||||
|         '#ergebnissForm\\:selectedSuchErgebnisFormTable_data' | ||||
|       ); | ||||
|       if (!tableBody) { | ||||
|         throw new Error('Table body not found'); | ||||
|       } | ||||
|  | ||||
|       // Locate the first row | ||||
|       const firstRow = tableBody.querySelector('tr:nth-child(1)'); | ||||
|       if (!firstRow) { | ||||
|         throw new Error('First row not found'); | ||||
|       } | ||||
|  | ||||
|       // Locate the last cell in the first row | ||||
|       const lastCell = firstRow.querySelector('td:last-child'); | ||||
|       if (!lastCell) { | ||||
|         throw new Error('Last cell not found in the first row'); | ||||
|       } | ||||
|  | ||||
|       // Locate the last <a> element in the last cell | ||||
|       const lastLink = lastCell.querySelector('a:last-of-type'); | ||||
|       if (!lastLink) { | ||||
|         throw new Error('Last link not found in the last cell'); | ||||
|       } | ||||
|  | ||||
|       // Simulate a click on the last <a> element | ||||
|       (lastLink as HTMLElement).click(); | ||||
|     }); | ||||
|  | ||||
|     // Optional: Wait for some response or navigation triggered by the click | ||||
|     await page.waitForTimeout(10000); | ||||
|  | ||||
|     page.off('response', responseListener); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user