|
|
|
@ -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) {
|
|
|
|
@ -193,39 +194,101 @@ export class HandelsRegister {
|
|
|
|
|
await page.waitForSelector('#form\\:schlagwoerter', { timeout: 5000 });
|
|
|
|
|
|
|
|
|
|
// 1) Type of Register:
|
|
|
|
|
// Open the dropdown to reveal options
|
|
|
|
|
await page.waitForSelector('#form\\:registerArt_label');
|
|
|
|
|
await page.click('#form\\:registerArt_label'); // Open the dropdown
|
|
|
|
|
// Open the dropdown to reveal options
|
|
|
|
|
await page.waitForSelector('#form\\:registerArt_label');
|
|
|
|
|
await page.click('#form\\:registerArt_label'); // Open the dropdown
|
|
|
|
|
|
|
|
|
|
// Wait for the options and select the one matching companyArg.type
|
|
|
|
|
await page.waitForSelector('#form\\:registerArt_items'); // Ensure dropdown options are loaded
|
|
|
|
|
await page.evaluate((type) => {
|
|
|
|
|
const options = Array.from(document.querySelectorAll('#form\\:registerArt_items li'));
|
|
|
|
|
const targetOption = options.find((option) => option.textContent?.trim() === type); // Match type dynamically
|
|
|
|
|
(targetOption as any)?.click();
|
|
|
|
|
}, companyArg.type); // Pass companyArg.type to the browser context
|
|
|
|
|
// Wait for the options and select the one matching companyArg.type
|
|
|
|
|
await page.waitForSelector('#form\\:registerArt_items'); // Ensure dropdown options are loaded
|
|
|
|
|
await page.evaluate((type) => {
|
|
|
|
|
const options = Array.from(document.querySelectorAll('#form\\:registerArt_items li'));
|
|
|
|
|
const targetOption = options.find((option) => option.textContent?.trim() === type); // Match type dynamically
|
|
|
|
|
(targetOption as any)?.click();
|
|
|
|
|
}, companyArg.type); // Pass companyArg.type to the browser context
|
|
|
|
|
|
|
|
|
|
// 2) Register number:
|
|
|
|
|
// Fill in the register number
|
|
|
|
|
await page.waitForSelector('#form\\:registerNummer');
|
|
|
|
|
await page.type('#form\\:registerNummer', companyArg.number);
|
|
|
|
|
// 2) Register number:
|
|
|
|
|
// Fill in the register number
|
|
|
|
|
await page.waitForSelector('#form\\:registerNummer');
|
|
|
|
|
await page.type('#form\\:registerNummer', companyArg.number);
|
|
|
|
|
|
|
|
|
|
// 3) Register court:
|
|
|
|
|
// Open the dropdown for the register court
|
|
|
|
|
await page.waitForSelector('#form\\:registergericht_label');
|
|
|
|
|
await page.click('#form\\:registergericht_label'); // Open the dropdown
|
|
|
|
|
// 3) Register court:
|
|
|
|
|
// Open the dropdown for the register court
|
|
|
|
|
await page.waitForSelector('#form\\:registergericht_label');
|
|
|
|
|
await page.click('#form\\:registergericht_label'); // Open the dropdown
|
|
|
|
|
|
|
|
|
|
// Wait for the options and select the one matching companyArg.court
|
|
|
|
|
await page.waitForSelector('#form\\:registergericht_items'); // Ensure dropdown options are loaded
|
|
|
|
|
await page.evaluate((court) => {
|
|
|
|
|
const options = Array.from(document.querySelectorAll('#form\\:registergericht_items li'));
|
|
|
|
|
const targetOption = options.find((option) => option.textContent?.trim() === court); // Match court dynamically
|
|
|
|
|
(targetOption as any)?.click();
|
|
|
|
|
}, companyArg.court); // Pass companyArg.court to the browser context
|
|
|
|
|
// Wait for the options and select the one matching companyArg.court
|
|
|
|
|
await page.waitForSelector('#form\\:registergericht_items'); // Ensure dropdown options are loaded
|
|
|
|
|
await page.evaluate((court) => {
|
|
|
|
|
const options = Array.from(document.querySelectorAll('#form\\:registergericht_items li'));
|
|
|
|
|
const targetOption = options.find((option) => option.textContent?.trim() === court); // Match court dynamically
|
|
|
|
|
(targetOption as any)?.click();
|
|
|
|
|
}, companyArg.court); // Pass companyArg.court to the browser context
|
|
|
|
|
|
|
|
|
|
await this.clickFindButton(page);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|