Skip to content

Commit

Permalink
Added Alodokter Scrape
Browse files Browse the repository at this point in the history
  • Loading branch information
MAYKELL07 committed Oct 25, 2023
1 parent 883e45a commit ed3de6e
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 101 deletions.
9 changes: 3 additions & 6 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TasksService } from './tasks/tasks.service';
import { TasksModule } from './tasks/tasks.module';
import { TasksController } from './tasks/tasks.controller';
import { ScraperService } from './scraper/scraper.service';
import { ScraperController } from './scraper/scraper.controller';
import { ScraperModule } from './scraper/scraper.module';

@Module({
imports: [TasksModule, ScraperModule],
controllers: [AppController, TasksController, ScraperController],
providers: [AppService, TasksService, ScraperService],
imports: [ScraperModule],
controllers: [AppController, ScraperController],
providers: [AppService, ScraperService],
})
export class AppModule {}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
await app.listen(3000)
}
bootstrap();
5 changes: 5 additions & 0 deletions src/scraper/scraper.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ export class ScraperController {
): Promise<string> {
return await this.scraperService.AI(prompt, AIName);
}

@Post('alodokter')
async scrapeAlodokter(@Body('inputText') inputText: string): Promise<string> {
return await this.scraperService.scrapeAlodokter(inputText);
}
}
11 changes: 11 additions & 0 deletions src/scraper/scraper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ export class ScraperService implements OnModuleInit, OnModuleDestroy {
return responseText;
}
}

async scrapeAlodokter(inputText: string): Promise<string> {
const context = await this.browser.newContext();
const page = await context.newPage();
await page.goto('https://www.alodokter.com');
await page.fill('#searchinput', inputText);
await page.click('div > div > div > a:nth-child(1)');
const paragraphText = await page.textContent('#postContent > p:nth-child(1)');
return paragraphText;
}

}
6 changes: 0 additions & 6 deletions src/tasks/task.model.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/tasks/tasks.controller.spec.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/tasks/tasks.controller.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/tasks/tasks.module.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/tasks/tasks.service.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/tasks/tasks.service.ts

This file was deleted.

0 comments on commit ed3de6e

Please sign in to comment.