-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
36 lines (27 loc) · 1.37 KB
/
bot.js
File metadata and controls
36 lines (27 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Import Puppeteer
const puppeteer = require('puppeteer');
// Firstly Define the bot as an asynchronous function
async function startBot() {
// Step 1: Launch the browser
const browser = await puppeteer.launch({
headless: false, // Set to true if you want to run without the GUI (headless mode)
defaultViewport: null, // Keep screen size open as default (or you can define it)
args: ['--start-maximized'] // Open in full screen
});
// Step 2: Open a new page
const page = await browser.newPage();
// Step 3: Navigate to desired website
await page.goto('https://www.google.com/'); // Replace with the target URL
// To Interact with the page by Clicking a button
await page.waitForSelector('button'); // Wait for a button to appear
await page.click('button'); // Click the button
// To Fill in a form input field (Example)
await page.type('input[name="q"]', 'Puppeteer Bot'); // Type into an input field
// To Take a screenshot
await page.screenshot({ path: 'screenshot.png' });
// To Close the browser after
await browser.close();
}
// Call the bot function to start
startBot().catch(error => console.error('Error in bot:', error));
// All dependencies and packages have been installed, only play around with the code adding desired website and required actions for bot