Skip to content

Commit 7f76db5

Browse files
committed
added 2nd selector <div.example-block>
1 parent d373be0 commit 7f76db5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/fetchTestCases.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export async function fetchTestCases(url: string): Promise<void> {
8888
console.log('Failed to fetch test cases after maximum retries.');
8989
}
9090
}
91+
9192
async function fetchTestCasesWithRetry(page: puppeteer.Page, url: string): Promise<any[]> {
9293
// Load cookies if available
9394
await loadCookies(page);
@@ -122,15 +123,15 @@ async function fetchTestCasesWithRetry(page: puppeteer.Page, url: string): Promi
122123
try {
123124
// Fallback to the .example-block structure
124125
console.log('Trying to extract test cases using .example-block structure...');
125-
await page.waitForSelector('.example-block', { timeout: 5000 }); // Adjust timeout as needed
126-
testCases = await page.$$eval('.example-block', (blocks) => {
126+
await page.waitForSelector('div.example-block', { timeout: 5000 }); // Adjust timeout as needed
127+
testCases = await page.$$eval('div.example-block', (blocks) => {
127128
return blocks.map(block => {
128-
const inputElement = block.querySelector('strong:contains("Input:") + span.example-io');
129-
const outputElement = block.querySelector('strong:contains("Output:") + span.example-io');
129+
const inputElement = Array.from(block.querySelectorAll('strong')).find(el => el.textContent?.includes("Input:"));
130+
const outputElement = Array.from(block.querySelectorAll('strong')).find(el => el.textContent?.includes("Output:"));
130131

131132
return {
132-
input: inputElement ? (inputElement as HTMLElement).innerText.trim() : null,
133-
output: outputElement ? (outputElement as HTMLElement).innerText.trim() : null,
133+
input: inputElement ? (inputElement.nextElementSibling as HTMLElement).innerText.trim() : null,
134+
output: outputElement ? (outputElement.nextElementSibling as HTMLElement).innerText.trim() : null,
134135
};
135136
});
136137
});
@@ -229,7 +230,6 @@ function extractRawData(input: string): string {
229230
return values.join(' ');
230231
}
231232

232-
233233
async function addAdditionalTestCases(count: number, existingCount: number): Promise<void> {
234234
const baseDirectory = path.join(__dirname, 'test_cases');
235235

@@ -262,4 +262,4 @@ const exampleTestCases = [
262262
}
263263
];
264264

265-
saveTestCasesToFiles(exampleTestCases);
265+
saveTestCasesToFiles(exampleTestCases);

0 commit comments

Comments
 (0)