Skip to content

Commit

Permalink
[feat🚀] Implement Remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexferrari88 committed Jun 13, 2022
1 parent c551143 commit 9c53411
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 265 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

All notable changes to this project will be documented in this file.

## [0.2.0] — 2022-06-13

### Added

- Remove action: it removes an element from the DOM. It can be useful when dealing with consent pop-ups.

## [0.1.0] — 2022-06-11

### Added

- ScreenshotToMap strategy (retrieve screenshot and maps with selectors for the specified elements)
- ScreenshotToMap strategy (retrieve screenshot and maps with selectors for the specified elements).

### Changed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Whether you are a scraping-hero or just want to monitor the price for that produ

- [Click on any element](src/scraping-actions/Click.ts)
- [Add cookie](src/scraping-actions/AddCookies.ts)
- [Remove an element](src/scraping-actions/Remove.ts)
- [Type anywhere you can type something](src/scraping-actions/Type.ts)
- [Press keyboard buttons (e.g. Enter, CTRL+C, etc.)](src/scraping-actions/Press.ts)
- [Scroll to bottom of the page](src/scraping-actions/Scroll.ts)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrapeblocks",
"version": "0.1.0",
"version": "0.2.0",
"description": "Scraping automation framework based on Playwright",
"main": "./dist/index.js",
"scripts": {
Expand Down
26 changes: 26 additions & 0 deletions src/scraping-actions/Remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BrowserContext, Page } from "playwright";
import { Action, ActionOptions } from "../types";
import { delay, validateOptions } from "../utils/utils";

type RemoveOptions = {
[P in keyof ActionOptions as Exclude<P, "cookies" | "value">]-?: ActionOptions[P];
};
export class Remove implements Action {
options: RemoveOptions;

constructor(options: RemoveOptions) {
validateOptions(options, {
element: "Remove action requires an element to remove",
});
this.options = options;
}

async execute(page: Page, _context?: BrowserContext): Promise<void> {
await page.$$eval(this.options.element, (elements) => {
elements.forEach((element) => {
element.remove();
});
});
await delay(100);
}
}
1 change: 1 addition & 0 deletions src/scraping-actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { AddCookies } from "./AddCookies";
export { Click } from "./Click";
export { Press } from "./Press";
export { Remove } from "./Remove";
export { Scroll } from "./Scroll";
export { Select } from "./Select";
export { Type } from "./Type";
Expand Down
Loading

0 comments on commit 9c53411

Please sign in to comment.