changed to save museum name
This commit is contained in:
15
src/index.ts
15
src/index.ts
@ -9,7 +9,7 @@ import chrome, { ServiceBuilder } from 'selenium-webdriver/chrome';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { getCities } from './lib/cities';
|
import { getCities } from './lib/cities';
|
||||||
import { WebDriverUtils, saveContactInfoToCSV, useExistingChrome, disableCookiesInChrome, useChrome } from './lib/utils';
|
import { WebDriverUtils, saveContactInfoToCSV, useExistingChrome, disableCookiesInChrome, useChrome, saveMuseumnameToCSV } from './lib/utils';
|
||||||
import * as UIActions from './lib/UIActions';
|
import * as UIActions from './lib/UIActions';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
|
||||||
@ -44,15 +44,15 @@ async function visitCityPages(): Promise<void> {
|
|||||||
await WebDriverUtils.wait(driver);
|
await WebDriverUtils.wait(driver);
|
||||||
|
|
||||||
let page = 1;
|
let page = 1;
|
||||||
let museumNames: string[] = [];
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
// get list of museums
|
// get list of museums
|
||||||
console.log("Get list of museums");
|
console.log("Get list of museums");
|
||||||
const tmpMuseumNames = await UIActions.getAttractionNames(driver);
|
const tmpMuseumNames = await UIActions.getAttractionNames(driver);
|
||||||
await WebDriverUtils.wait(driver);
|
|
||||||
museumNames = [...museumNames, ...tmpMuseumNames]
|
if (tmpMuseumNames.length == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
page++;
|
page++;
|
||||||
|
|
||||||
@ -61,8 +61,13 @@ async function visitCityPages(): Promise<void> {
|
|||||||
UIActions.clickPagination(driver, page);
|
UIActions.clickPagination(driver, page);
|
||||||
await WebDriverUtils.wait(driver);
|
await WebDriverUtils.wait(driver);
|
||||||
|
|
||||||
|
tmpMuseumNames.forEach((museumName) => {
|
||||||
|
saveMuseumnameToCSV(city, museumName, path.join(__dirname, '../data/museums.csv'));
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for (const museumName of museumNames) {
|
for (const museumName of museumNames) {
|
||||||
|
|
||||||
console.log("back to home");
|
console.log("back to home");
|
||||||
@ -84,7 +89,7 @@ async function visitCityPages(): Promise<void> {
|
|||||||
|
|
||||||
console.log(museumNames);
|
console.log(museumNames);
|
||||||
await UIActions.closeAllTabsExceptFirst(driver);
|
await UIActions.closeAllTabsExceptFirst(driver);
|
||||||
|
*/
|
||||||
|
|
||||||
if (i < cities.length - 1) {
|
if (i < cities.length - 1) {
|
||||||
console.log(`Waiting for 5000 seconds before next city...`);
|
console.log(`Waiting for 5000 seconds before next city...`);
|
||||||
|
|||||||
@ -69,6 +69,20 @@ export function saveContactInfoToCSV(city: string, contactInfo: ContactInfo, fil
|
|||||||
console.log(`Contact info saved to ${filePath}`);
|
console.log(`Contact info saved to ${filePath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function saveMuseumnameToCSV(city: string, museumName: string, filePath: string): void {
|
||||||
|
const headers = 'City,Website URL,Email\n';
|
||||||
|
const line = `"${city},"${museumName}"\n`;
|
||||||
|
|
||||||
|
if (!existsSync(filePath)) {
|
||||||
|
writeFileSync(filePath, headers + line);
|
||||||
|
} else {
|
||||||
|
appendFileSync(filePath, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Museum name saved to ${filePath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function disableCookiesInChrome(): Promise<WebDriver | null> {
|
export async function disableCookiesInChrome(): Promise<WebDriver | null> {
|
||||||
// Set Chrome options
|
// Set Chrome options
|
||||||
const options = new chrome.Options();
|
const options = new chrome.Options();
|
||||||
|
|||||||
Reference in New Issue
Block a user