Skip to content

Commit 79e99dc

Browse files
committed
style: use 'selection' to call Cheerio objects
1 parent 0a2a15e commit 79e99dc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sources/academy/webscraping/scraping_basics_javascript2/05_parsing_html.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ LoadedCheerio {
9292
}
9393
```
9494

95-
Our code prints a Cheerio object. It's something like an array of all `h1` elements Cheerio can find in the HTML we gave it. It's the case that there's just one, so we can see only a single item in the container.
95+
Our code prints a Cheerio object. It's something like an array of all `h1` elements Cheerio can find in the HTML we gave it. It's the case that there's just one, so we can see only a single item in the selection.
9696

9797
The item has many properties, such as references to its parent or sibling elements, but most importantly, its name is `h1` and in the `children` property, it contains a single text element. Now let's print just the text. Let's change our program to the following:
9898

@@ -112,7 +112,7 @@ if (response.ok) {
112112
}
113113
```
114114

115-
Thanks to the nature of the Cheerio object we don't have to explicitly find the first element. If we call `.text()`, it automatically assumes we want to work with the first element in the collection. Thus, if we run our scraper again, it prints the text of the first `h1` element:
115+
Thanks to the nature of the Cheerio object we don't have to explicitly find the first element. Calling `.text()` combines texts of all elements in the selection. If we run our scraper again, it prints the text of the `h1` element:
116116

117117
```text
118118
$ node index.js
@@ -147,7 +147,7 @@ if (response.ok) {
147147
}
148148
```
149149

150-
In CSS, `.product-item` selects all elements whose `class` attribute contains value `product-item`. We call `$()` with the selector and get back a container of matching elements. Cheerio handles all the complexity of understanding the HTML markup for us. Then we use `.length` to count how many items there is in the container.
150+
In CSS, `.product-item` selects all elements whose `class` attribute contains value `product-item`. We call `$()` with the selector and get back matching elements. Cheerio handles all the complexity of understanding the HTML markup for us. Then we use `.length` to count how many items there is in the selection.
151151

152152
```text
153153
$ node index.js

0 commit comments

Comments
 (0)