Compare commits

..

2 Commits

Author SHA1 Message Date
b6cad2a241 Merge branch 'main' of https://git.yasue.org/ken/tripadviser_scraper 2025-03-24 06:47:48 +01:00
6f36809932 wip 2025-03-24 06:47:38 +01:00
2 changed files with 13 additions and 12 deletions

View File

@ -41,7 +41,7 @@ async function visitCityPages(): Promise<void> {
console.log("Logo click")
if (!await UIActions.gotoHome(driver)) throw `${city} failed`;
await WebDriverUtils.wait(5);
await WebDriverUtils.wait();
console.log("Exec Search")
if (!await UIActions.execSearch(driver, city)) throw `${city} failed`;
@ -52,7 +52,7 @@ async function visitCityPages(): Promise<void> {
if (!await UIActions.clickTourismLink(driver)) throw `${city} failed`;
if (!await UIActions.clickSeeAll(driver)) throw `${city} failed`;
}
await WebDriverUtils.wait(5);
await WebDriverUtils.wait();
console.log("Switch tab")
let windows = await driver.getAllWindowHandles();
@ -66,7 +66,7 @@ async function visitCityPages(): Promise<void> {
console.log("Click See all attractions")
if (!await UIActions.clickSeeAllAttractions(driver)) throw `${city} failed`;
await WebDriverUtils.wait(5);
await WebDriverUtils.wait();
console.log("Switch tab to Attraction")
windows = await driver.getAllWindowHandles();
@ -81,7 +81,7 @@ async function visitCityPages(): Promise<void> {
// click museum
console.log("Click Museum link");
if (!await UIActions.clickMuseumsLink(driver)) throw `${city} failed`;
await WebDriverUtils.wait(5);
await WebDriverUtils.wait();
let page = 1;
while (1) {
@ -89,12 +89,12 @@ async function visitCityPages(): Promise<void> {
// get list of museums
console.log("Get list of museums");
const museumElms = await UIActions.getMusiums(driver);
await WebDriverUtils.wait(1);
await WebDriverUtils.wait();
for (const listItem of museumElms) {
await listItem.click();
await WebDriverUtils.wait(3);
await WebDriverUtils.wait();
windows = await driver.getAllWindowHandles();
for (const handle of windows) {
@ -111,10 +111,10 @@ async function visitCityPages(): Promise<void> {
museumWindow && await driver.switchTo().window(museumWindow);
await driver.close();
await WebDriverUtils.wait(1);
await WebDriverUtils.wait();
attactionsWindow && await driver.switchTo().window(attactionsWindow);
await WebDriverUtils.wait(1);
await WebDriverUtils.wait();
}
@ -123,7 +123,7 @@ async function visitCityPages(): Promise<void> {
if (page > 10) break;
UIActions.clickPagination(driver, page);
await WebDriverUtils.wait(5);
await WebDriverUtils.wait();
}
@ -133,7 +133,7 @@ async function visitCityPages(): Promise<void> {
if (i < cities.length - 1) {
console.log(`Waiting for 5000 seconds before next city...`);
await WebDriverUtils.wait(5); // Wait 5000 seconds before next city
await WebDriverUtils.wait(); // Wait 5000 seconds before next city
}
} catch (error) {
@ -141,7 +141,7 @@ async function visitCityPages(): Promise<void> {
// If the button is not found within the timeout, log and continue to the next city
console.log(`No Museums button found for ${city}. Moving to next city after 5 seconds...`);
await WebDriverUtils.wait(5); // Wait 5 seconds before next city
await WebDriverUtils.wait(); // Wait 5 seconds before next city
}
}

View File

@ -14,7 +14,8 @@ export class WebDriverUtils {
* @param seconds Number of seconds to wait
* @returns Promise that resolves after the specified time
*/
static async wait(seconds: number): Promise<void> {
static async wait(seconds: number = 3): Promise<void> {
seconds = Math.floor(Math.random() * 1000) % 3 + 3;
console.log(`Waiting for ${seconds} seconds...`);
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}