Document not found (404)
-This URL is invalid, sorry. Please use the navigation bar or search to continue.
- -diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e9c0728 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +book \ No newline at end of file diff --git a/book/.nojekyll b/book/.nojekyll deleted file mode 100644 index f173110..0000000 --- a/book/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -This file makes sure that Github Pages doesn't process mdBook's output. diff --git a/book/404.html b/book/404.html deleted file mode 100644 index 42cacee..0000000 --- a/book/404.html +++ /dev/null @@ -1,234 +0,0 @@ - - -
- - -This URL is invalid, sorry. Please use the navigation bar or search to continue.
- -To use Puppeteer in your project, run:
-npm install puppeteer
-# or
-yarn add puppeteer
-# or
-pnpm add puppeteer
-
-When you install Puppeteer, it automatically downloads a recent version of Chrome for Testing (~170MB macOS, ~282MB Linux, ~280MB Windows) and a chrome-headless-shell binary
that is guaranteed to work with Puppeteer. The browser is downloaded to the $HOME/.cache/puppeteer folder by default
Puppeteer is a Node.js library which provides a high-level API to control Chrome/Chromium over the DevTools Protocol. While it's primarily used for automating web tasks, Puppeteer can also be used for web scraping, testing, and creating snapshots of web pages.
- - - - -Most things that you can do manually in the browser can be done using Puppeteer! Here are a few examples to get you started:
-Having multiple branches is extremely convenient to keep new changes separated and avoid pushing unapproved or broken changes to production. When the changes are approved, integrating them into the production branch is essential.
-A fast-forward merge occurs when the current branch has no additional commits compared to the branch being merged. Git prefers this as the easiest option: it merges the commit(s) from the branch being merged into the current branch without creating a new commit.
- -In case the current branch has commits not present in the branch to be merged, Git performs a no-fast-forward merge. This creates a new merging commit on the active branch, integrating changes from both branches.
- -Merging branches with conflicting changes in the same lines or with deleted files that were modified elsewhere can cause merge conflicts. Git highlights these conflicts, enabling manual resolution by removing unwanted changes, saving, re-adding the changed file, and committing the changes.
- -Git rebase copies commits from the current branch and places them on top of the specified branch. Unlike merging, rebasing doesn't attempt to decide which files to keep, maintaining the branch's latest changes and avoiding merging conflicts.
- -Rebasing is ideal when integrating updates from the master branch into a feature branch, preventing future merging conflicts.
-Interactive rebase allows modification of commits before rebasing, offering six actions:
-Feel free to use these actions for full control over your commits, whether removing or merging them. Interactive rebase facilitates the modification of commits.
-A soft reset shifts HEAD to the specified commit without discarding changes introduced by the following commits. It preserves access to the changes made in the previous commits, enabling fixing and recommitting them later.
- -A hard reset returns Git's state to the specified commit, including changes in the working directory and staged files, discarding all changes introduced after the commit.
- -Git revert creates a new commit that undoes the changes introduced by the specified commit, ensuring the commit history remains unaltered.
- -Git revert is useful for undoing a specific commit without altering the branch's history.
- -Pull requests simplify collaboration using GitHub. They notify project maintainers about changes in a forked repository, making it easier to review and discuss proposed changes before integration into the official project. Pull requests are commonly used to propose changes, notify maintainers about changes in a forked repository, discuss proposed changes, and collaborate with other developers.
-When submitted, pull requests are reviewed by project maintainers. They can approve, request changes, or close the request. They're an excellent way to contribute to open source projects and gain experience with Git and GitHub. Merging pull requests offers two options:
-git init
: Initialize a new Git repository.git add <file>
: Add changes to the staging area.git commit -m "message"
: Commit changes with a descriptive message.git status
: Check the status of your working directory.git log
: View the commit history.git diff
: View changes made to a file.git checkout <branch>
: Switch to a different branch. Use git checkout -b <branch>
to create a new branch.git reset <file>
: Remove a file from the staging area.git rm <file>
: Remove a file from the working directory and staging area.git mv <file> <new file>
: Rename a file and stage the change.git remote add origin <url>
: Add a remote repository.git push origin <branch>
: Push changes to a remote repository.git pull origin <branch>
: Pull changes from a remote repository.git clone <url>
: Clone a remote repository to your local machine.git merge <branch>
: Merge a branch into the active branch.git fetch
: Download changes from a remote repository.git stash
: Temporarily store changes that you don't want to commit.git push --force
: Force push changes to a remote repository (Use with caution).Usually, you start working with Puppeteer by launching a browser instance. This browser instance is controlled by Puppeteer and can be used to open new tabs, navigate to different URLs, interact with web pages, and perform various tasks.
-import puppeteer from "puppeteer";
-
-const browser = await puppeteer.launch();
-
-const page = await browser.newPage();
-
-When launching a browser, you can specify various options to customize its behavior. These options include:
-headless
: A boolean value that determines whether the browser should run in headless mode (without a visible UI). By default, this option is set to true
.slowMo
: A number that introduces a delay (in milliseconds) between Puppeteer actions. This can be useful for debugging or observing the automation process.defaultViewport
: An object that defines the initial browser window size and scale factor. This can be useful for ensuring consistent rendering across different devices.args
: An array of strings that specify additional command-line arguments to pass to the browser instance. These arguments can modify the browser's behavior or enable specific features.const browser = await puppeteer.launch({
- headless: false,
- slowMo: 250,
- defaultViewport: null,
- args: ["--start-maximized"],
-});
-
-Once you're done working with the browser, you should close it to free up system resources. You can close the browser instance using the browser.close()
method.
import puppeteer from "puppeteer";
-
-const browser = await puppeteer.launch();
-
-const page = await browser.newPage();
-
-await browser.close();
-
-
- At the heart of Puppeteer lies the concept of a browser and a page. The browser represents the Chrome or Chromium instance controlled by Puppeteer, while the page represents a single tab within that browser instance. Think of the browser as your window to the internet, and each page as a separate document or website within that window.
-Selectors are a fundamental aspect of web automation, allowing you to pinpoint and interact with specific elements on a web page. Puppeteer leverages various types of selectors, including:
-Understanding selectors is crucial for navigating and manipulating web pages effectively with Puppeteer. They serve as the building blocks for automating interactions such as clicking buttons, inputting text, or extracting data from specific elements.
- -In this section, we will learn how to interact with a page using Puppeteer. Puppeteer provides a high-level API to interact with a page, which includes navigating to a page, clicking on elements, typing text, and more. All the functions are asynchronous and return promises, which makes it easy to work with Puppeteer in an asynchronous manner. There are many methods available to interact with a page, and we will cover some of the most common ones, but you can find the full list in the official documentation.
-To navigate to a page, you can use the page.goto()
method. This method takes a URL as an argument and loads the page at the specified URL.
import puppeteer from "puppeteer";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
-
- await page.goto("https://www.example.com");
-
- await browser.close();
-})();
-
-In the example above, we launch a browser instance, create a new page, and navigate to https://www.example.com
. Once the page is loaded, we close the browser.
You can take a screenshot of a page using the page.screenshot()
method. This method captures a screenshot of the current page and saves it to a file, to the specified path.
import puppeteer from "puppeteer";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
-
- await page.goto("https://www.example.com");
- await page.screenshot({ path: "example.png", fullPage: true });
-
- await browser.close();
-})();
-
-You can generate a PDF of a page using the page.pdf()
method. This method generates a PDF of the current page and saves it to a file, to the specified path.
import puppeteer from "puppeteer";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
-
- await page.goto("https://www.example.com");
- await page.pdf({ path: "example.pdf", format: "A4" });
-
- await browser.close();
-})();
-
-page.$(selector)
: This method returns the first element that matches the specified selector. If no element matches the selector, the method returns null
.page.$$(selector)
: This method returns an array of elements that match the specified selector. If no elements match the selector, the method returns an empty array.page.$eval(selector, pageFunction, ...args)
: This method evaluates the specified function in the context of the first element that matches the selector. The function can access the DOM of the element and return a value. The arguments passed to the function are serialized and can be accessed as function parameters.page.evaluate(pageFunction, ...args)
: This method evaluates the specified function in the context of the page. The function can access the DOM of the page and return a value. The arguments passed to the function are serialized and can be accessed as function parameters.When evaluating JavaScript on a page, you can interact with elements, get their attributes, and perform various actions. This allows you to automate tasks, scrape data, and test web applications.
-import puppeteer from "puppeteer";
-
-const selector = ".selector";
-const textSelector = ".text-selector";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
- await page.goto("https://www.example.com");
-
- const element = await page.$(selector); // Get the first element that matches the selector
- const elements = await page.$$(selector); // Get all elements that match the selector
-
- let value = await page.$eval(selector, (element) => {
- return element..innerText;
- });
-
- value = await page.evaluate((selector) => {
- return document.querySelector(selector).textContent;
- }, selector);
-
- const text = await element.evaluate((el) => el.textContent); // Get the text content of the element
-})();
-
-When interacting with a page, it's important to wait for elements to be available before performing actions on them. Puppeteer provides the page.waitForSelector()
method to wait for an element to be present in the DOM. By default, this method waits for 30 seconds before timing out, but you can specify a custom timeout using the timeout
option.
import puppeteer from "puppeteer";
-
-const selector = ".selector";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
- await page.goto("https://www.example.com");
-
- await page.waitForSelector(selector, { timeout: 5000 });
-
- await browser.close();
-})();
-
-Also, it's advisable to insert some delay before performing actions on the page. This can be done creating a delay function and using it before performing actions.
-function delay(time) {
- return new Promise(function (resolve) {
- setTimeout(resolve, time);
- });
-}
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
- await page.goto("https://www.example.com");
-
- await delay(2000); // Wait for 2 seconds
-
- await browser.close();
-})();
-
-To click on an element on a page, you can use the element.click()
method. This method simulates a mouse click on the element. While this method seems pretty straightforward, in some cases, the element might not be completely visible or clickable, that's why it's more recommended to use the evaluation methods mentioned above.
import puppeteer from "puppeteer";
-
-const selector = ".selector";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
- await page.goto("https://www.example.com");
-
- await page.waitForSelector(selector);
-
- const element = await page.$(selector);
-
- await element.click();
-
- // safer approach
- await element.evaluate((el) => el.click());
-
- await browser.close();
-})();
-
-For input fields, you can use the element.type()
method to type text into the field. This method simulates typing text on the keyboard and is useful for automating form submissions, login processes, and more.
import puppeteer from "puppeteer";
-
-const selector = ".selector";
-
-(async () => {
- const browser = await puppeteer.launch();
- const page = await browser.newPage();
- await page.goto("https://www.example.com");
-
- await page.waitForSelector(selector);
-
- const element = await page.$(selector);
-
- await element.type("Hello, World!");
-
- await browser.close();
-})();
-
-
- The objective of this task is to update the gdsc.txt
file in repositories owned by other participants with your personal information.
Create a New Branch:
-In your terminal, create a new branch for your changes using:
-git checkout -b {your-name}
However, it's best practice to use a descriptive name that reflects the purpose of the branch. In this case, you can use your own name as the branch name, to avoid branch name clashes with the other participants.
-Open gdsc.txt
:
Update gdsc.txt
:
gdsc.txt
file and add your name, occupation, favorite hobby, and something you dislike in the existing format, similarly to how the repository owner has added their information.Save Changes:
-gdsc.txt
file.Stage Changes:
-git add gdsc.txt
-
-Commit Changes:
-git commit -m "Added personal information to gdsc.txt"
-
-Push to Repository:
-git push --set-upstream origin {branch-name}
In this section, we'll cover the process of cloning repositories from GitHub onto your local machine.
-Each participant sitting at the same table should share their repository URL. This URL can be obtained from their GitHub repository.
-If the repositories are private, participants need to grant access permissions to others. Ask the repository owner to grant access to you by having him follow these steps:
-Collaborators and Teams
from the sidebar.Manage access
, click on Add people
.For each participant, follow these steps to clone the repository to your local machine:
-a. Open your terminal or Git Bash.
-b. Use the git clone
command followed by the repository URL:
git clone <repository_URL>
-
-c. This will create a local copy of the repository on your machine.
-If all went well with adding an SSH key in the previous exercise, you should be able to clone the repository without any issues. If you're still having trouble, ask for a volunteer to help you out.
-Once the cloning process is completed, navigate into the cloned directory using the cd
command in the terminal to ensure the repository has been successfully cloned.
Following these steps will allow each participant to clone repositories onto their local machines, enabling them to contribute and collaborate effectively.
- -Navigate to the Repository:
-Switch to the Branch:
-Click on "New Pull Request":
-Compare Changes:
-Add Title and Description:
-Review Changes:
-Assign Reviewers (If Required):
-Labels, Milestones, and Projects (Optional):
-Create the Pull Request:
-Welcome to the Git Essentials second exercise! In this exercise, you'll dive into resolving merge conflicts in a collaborative Git environment. The focus will be on updating personal information in a shared file, generating merge conflicts, and exploring different conflict resolution strategies. Here's the tasks you'll be performing:
-Updating Your Profile:
-gdsc.txt
file in repositories belonging to your fellow participants. Add your name, occupation, favorite hobby, and something you dislike to their gdsc.txt
.Creating Pull Requests:
-gdsc.txt
file.Simulating Merge Conflicts:
-gdsc.txt
file in repositories of other participants.Resolving Conflicts:
-git status
, git diff
, git checkout --ours/--theirs
) to identify conflicting sections.Exploring Git Strategies:
-Reviewing Commit History and Interactive Rebase:
-git log
.Git's log
command offers a view of the commit history. It displays a list of commits in reverse chronological order, showcasing commit messages, authors, and commit hashes. Participants can enter git log
in the terminal to view the commit history of a repository, gaining insights into the project's development timeline.
Let's explore the functionality of interactive rebase, focusing on squashing commits, changing messages, deleting, and picking commits in a simple exercise.
-Squashing Commits:
-git rebase -i HEAD~N
, where N
is the number of commits to include.Changing Commit Messages:
-reword
.Deleting Commits:
-git rebase -i
.Picking Commits:
-git rebase -i
.In the GitHub Pull Request UI, when merging a pull request, three distinct options are available:
-Create Merge Commit:
-Squash and Merge:
-Rebase and Merge:
-Each option offers a distinct approach to integrating changes from a pull request, allowing contributors to select the method that best aligns with the project's version control and commit history preferences. These options significantly influence the resulting commit history and repository structure.
- -Ideally, each repository should have at least two Pull Requests (PRs) modifying the same gdsc.txt
file with contact information. Merging one PR may cause a conflict in the other PR due to changes in the same file.
The primary difference between the merge and rebase approaches lies in how they integrate changes.
-Merge combines the commit histories of the divergent branches, creating a new commit that reflects the combined changes. It retains the original commit history but may result in "merge commits," which explicitly mark where the branches were merged.
-Rebase, on the other hand, rewrites the commit history by placing the local branch's commits on top of the latest changes from the main branch. This creates a linear and cleaner history but alters commit timestamps.
-Checkout the Branch:
-git checkout branch-name
Pull the Latest Changes:
-git pull origin main
Resolve Conflicts Locally:
-gdsc.txt
file in your code editor.<<<<<<<
, =======
, >>>>>>>
) denote conflicting sections.Stage and Commit Changes:
-git add gdsc.txt
git commit -m "Resolved merge conflict in gdsc.txt"
Push Changes to the Branch:
-git push origin branch-name
Merge the PR:
-Checkout the Branch:
-git checkout branch-name
Rebase from Main:
-git rebase main
Resolve Conflicts:
-Continue Rebase:
-git rebase --continue
Push the Rebased Changes:
-git push --force origin branch-name
Merge the PR:
-Welcome, fellow developers and enthusiasts, to a workshop that will illuminate the path to mastering one of the most powerful tools in the web automation arsenal – Puppeteer. Developed by Google, Puppeteer is more than just a library; it's a gateway to automating tasks, testing websites, and breathing life into your web projects.
-Just as Git revolutionizes collaboration in the coding world, Puppeteer empowers developers to navigate the digital landscape with precision and finesse. With Puppeteer as your companion, you'll embark on a journey where virtual pages become your canvas, and scripts wield the power to interact with web elements, simulate user actions, and extract valuable insights.
-Throughout this workshop, we'll dive into the intricacies of Puppeteer, unraveling its capabilities, exploring practical use cases, and equipping you with the skills to wield this tool effectively. Whether you're a seasoned developer or a curious novice, Puppeteer offers a gateway to a world where automation is not just a convenience but a game-changer.
-As promised, we'll look into ways of finding rent in Cluj Napoca in a more efficient way. So, get ready to dive into the world of Puppeteer, where lines of code become puppet strings, and the web transforms into your stage. Let's embark on this journey together, where every click, every scroll, and every interaction is powered by the magic of Puppeteer. Your apartment in Cluj Napoca awaits!
- -