Skip to content

Commit 9fa2ac3

Browse files
committed
wip
1 parent d3406ef commit 9fa2ac3

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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';
89
import Exercises from '../scraping_basics/_exercises.mdx';
910

1011
**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.**
@@ -150,14 +151,23 @@ https://www.aliexpress.com/w/wholesale-darth-vader.html
150151
<details>
151152
<summary>Solution</summary>
152153

153-
```py
154-
import httpx
154+
<TestedExercise>
155+
```py
156+
import httpx
155157

156-
url = "https://www.aliexpress.com/w/wholesale-darth-vader.html"
157-
response = httpx.get(url)
158-
response.raise_for_status()
159-
print(response.text)
160-
```
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>
161171

162172
</details>
163173

src/components/TestedExercise.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function TestedExercise({ children }) {
2+
const [exerciseCode, testCode] = children;
3+
if (testCode.props.className !== 'language-bats') {
4+
throw new Error('Exercise: Expected second child to be a Bats code block with tests');
5+
}
6+
return exerciseCode;
7+
}
8+
9+
// TODO write docusaurus plugin to extract the exercises and tests from the MDX files

0 commit comments

Comments
 (0)