Skip to content

Commit 4dc5517

Browse files
committed
feat: finalize exercises
1 parent 10720fd commit 4dc5517

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

sources/academy/webscraping/scraping_basics_python/02_devtools_locating_elements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Go to Guardian's [page about F1](https://www.theguardian.com/sport/formulaone).
198198

199199
Hint: Learn about the [descendant combinator](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator).
200200

201-
![Articles on Guardian's page about F1](./images/devtools-exercise-guardian.png)
201+
![Articles on Guardian's page about F1](./images/devtools-exercise-guardian1.png)
202202

203203
<details>
204204
<summary>Solution</summary>

sources/academy/webscraping/scraping_basics_python/03_devtools_extracting_data.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ On Fandom's [Movies page](https://www.fandom.com/topics/movies), use CSS selecto
9797

9898
</details>
9999

100-
101100
### Extract the price of IKEA's most expensive artificial plant
102101

103102
At IKEA's [Artificial plants & flowers listing](https://www.ikea.com/se/en/cat/artificial-plants-flowers-20492/), use CSS selectors, and HTML elements manipulation in the **Console** to extract the price of the most expensive artificial plant (sold in Sweden, as we'll be browsing their Swedish offer). Before opening DevTools, use your wits to set the page to a state which is most favorable for you to complete the task with the least effort. In the end, use JavaScript's [`parseInt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) to turn the text to a number.
@@ -116,3 +115,23 @@ At IKEA's [Artificial plants & flowers listing](https://www.ikea.com/se/en/cat/a
116115
1. At the time of writing, this returns `699`, as in [699 SEK](https://www.google.com/search?q=699%20sek).
117116

118117
</details>
118+
119+
### Extract details about the first post on Guardian's F1 news
120+
121+
At Guardian's [F1 news page](https://www.theguardian.com/sport/formulaone), use CSS selectors and HTML manipulation in the **Console** to extract details about the first post. Extract its title, lead paragraph, and URL of the photo.
122+
123+
![F1 news page](./images/devtools-exercise-guardian2.png)
124+
125+
<details>
126+
<summary>Solution</summary>
127+
128+
1. Open the [F1 news page](https://www.theguardian.com/sport/formulaone).
129+
1. Activate the element selection tool in your DevTools.
130+
1. Click on the first post.
131+
1. Notice that there are no good classes to go by. The markup uses generic tags and randomized classes. We must rely on the hierarchy and order of the elements instead.
132+
1. In the **Console**, execute `post = document.querySelector('#maincontent ul li')`. It returns element representing the first post.
133+
1. In the **Console**, execute `post.querySelector('h3').textContent` to extract the title.
134+
1. In the **Console**, execute `post.querySelector('span div').textContent` to extract the lead paragraph.
135+
1. In the **Console**, execute `post.querySelector('img').src` to extract the photo URL.
136+
137+
</details>
-85.5 KB
Loading
760 KB
Loading

0 commit comments

Comments
 (0)