Skip to content

Commit 05099c1

Browse files
committed
feat: keep exercises as separate files, include them to Markdown
1 parent 9fa2ac3 commit 05099c1

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

sources/academy/webscraping/scraping_basics_python/04_downloading_html.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ description: Lesson about building a Python application for watching prices. Usi
55
slug: /scraping-basics-python/downloading-html
66
---
77

8-
import TestedExercise from '@site/src/components/TestedExercise';
8+
import CodeBlock from '@theme/CodeBlock';
99
import Exercises from '../scraping_basics/_exercises.mdx';
10+
import LegoExercise from '!!raw-loader!roa-loader!./exercises/scrape_lego.py';
1011

1112
**In this lesson we'll start building a Python application for watching prices. As a first step, we'll use the HTTPX library to download HTML code of a product listing page.**
1213

@@ -140,35 +141,17 @@ Letting our program visibly crash on error is enough for our purposes. Now, let'
140141

141142
<Exercises />
142143

143-
### Scrape AliExpress
144+
### Scrape LEGO
144145

145-
Download HTML of a product listing page, but this time from a real world e-commerce website. For example this page with AliExpress search results:
146+
Download HTML of a product listing page, but this time from a real world e-commerce website. For example this page with LEGO search results:
146147

147148
```text
148-
https://www.aliexpress.com/w/wholesale-darth-vader.html
149+
https://www.lego.com/themes/star-wars
149150
```
150151

151152
<details>
152153
<summary>Solution</summary>
153-
154-
<TestedExercise>
155-
```py
156-
import httpx
157-
158-
url = "https://www.aliexpress.com/w/wholesale-darth-vader.html"
159-
response = httpx.get(url)
160-
response.raise_for_status()
161-
print(response.text)
162-
```
163-
164-
```bats
165-
@test "outputs the HTML with darth vader products" {
166-
run uv python exercise.py
167-
assert_output --partial 'Need more help to find the most popular darth vader?'
168-
}
169-
```
170-
</TestedExercise>
171-
154+
<CodeBlock language="py">{LegoExercise.code}</CodeBlock>
172155
</details>
173156

174157
### Save downloaded HTML as a file
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import httpx
2+
3+
url = "https://www.lego.com/themes/star-wars"
4+
response = httpx.get(url)
5+
response.raise_for_status()
6+
print(response.text)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
setup() {
2+
DIR=sources/academy/webscraping/scraping_basics_python/exercises
3+
}
4+
5+
@test "outputs the HTML with Star Wars products" {
6+
run uv run --with httpx python "$DIR/scrape_lego.py"
7+
[[ "$output" == *"Millennium Falcon"* ]]
8+
}

src/components/TestedExercise.jsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)