ALL4S (All Fours) 🥾
A simple web crawling automation tool.
This package simplifies and streamlines a puppeteer instance in order to make web crawling and automation a touch easier.
npm install all4s
All promises resolve to 'null' if no elements are found. This is done by design in order to make sure automation scripts don't throw, you can handle a null return easily too :)
Getting Started 🎬
- Import
all4s
import { ALL4S } from "all4s";
- Create an ALL4S instance within an async scope and kick it off ⚽.
(async () => {
const allFours = new ALL4S({
startPage: 'https://www.haydncomley.com/',
debug: true,
debugHideConsole: false,
browserOptions: {}
});
await allFours.doStart();
})();
- Start automating your web crawler.
const aButton = await allFours.getAnElement('#my-button');
await allFours.eventClick(cookieButton);
const anInput = await allFours.getAnElement('#my-input');
await allFours.eventType(anInput, 'This is some text input.');
Get element by text 📝
- You can get an element by searching for it's text content if other selectors are no use.
const cookieButton = await allFours.getAnElementThatContainsText('button', 'I Accept');
await allFours.eventClick(cookieButton);
- You can also specify how many times this text needs to show up for certain edge cases.
const confirmationParagraph = await allFours.getAnElementThatContainsText('p', 'yes', 3);
Wait for element to show up ⌚
- You can wait until an element shows up and then have it returned. Either wait eternally or set a timeout.
const cookiePopup = await allFours.doWaitFor(() => allFours.getAnElement('#cookie-consent'));
const cookiePopup = await allFours.doWaitFor(() => allFours.getAnElement('#cookie-consent'), 5000);
allFours.doWaitFor(() => allFours.getAnElementThatContainsText('button', 'I Accept')).then((button) => {
allFours.eventClick(button)
});
Get Element Value / Property / Attribute 👗
- You can grab properties from elements with this simple api.
const href = await allFours.getValueFromElement<String, HTMLAnchorElement>(element, 'href');
Delay Executing / Sleep 🦥
- All actions have waiting built in, but you can always wait some more if needed.
await allFours.doDelay(1000);
Navigation 🗺
- Navigate to another page.
await allFours.doNavigation('https://haydncomley.com');