Skip to content

Commit 01e63ec

Browse files
committed
style: make Python course consistent with the (new) JS one
1 parent c6f3807 commit 01e63ec

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

sources/academy/webscraping/scraping_basics_python/08_saving_data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ for product in soup.select(".product-item"):
6565
print(data)
6666
```
6767

68-
Before looping over the products, we prepare an empty list. Then, instead of printing each line, we append the data of each product to the list in the form of a Python dictionary. At the end of the program, we print the entire list at once.
68+
Before looping over the products, we prepare an empty list. Then, instead of printing each line, we append the data of each product to the list in the form of a Python dictionary. At the end of the program, we print the entire list. The program should now print the results as a single large Python list:
6969

7070
```text
7171
$ python main.py

sources/academy/webscraping/scraping_basics_python/10_crawling.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Depending on what's valuable for our use case, we can now use the same technique
120120
It looks like using a CSS selector to locate the element with the `product-meta__vendor` class, and then extracting its text, should be enough to get the vendor name as a string:
121121

122122
```py
123-
vendor = product_soup.select_one(".product-meta__vendor").text.strip()
123+
vendor = soup.select_one(".product-meta__vendor").text.strip()
124124
```
125125

126126
But where do we put this line in our program?
@@ -130,8 +130,6 @@ But where do we put this line in our program?
130130
In the `data` loop we're already going through all the products. Let's expand it to include downloading the product detail page, parsing it, extracting the vendor's name, and adding it as a new key in the item's dictionary:
131131

132132
```py
133-
...
134-
135133
listing_url = "https://warehouse-theme-metal.myshopify.com/collections/sales"
136134
listing_soup = download(listing_url)
137135

@@ -143,8 +141,6 @@ for product in listing_soup.select(".product-item"):
143141
# highlight-next-line
144142
item["vendor"] = product_soup.select_one(".product-meta__vendor").text.strip()
145143
data.append(item)
146-
147-
...
148144
```
149145

150146
If we run the program now, it'll take longer to finish since it's making 24 more HTTP requests. But in the end, it should produce exports with a new field containing the vendor's name:
@@ -172,7 +168,7 @@ If we run the program now, it'll take longer to finish since it's making 24 more
172168

173169
## Extracting price
174170

175-
Scraping the vendor's name is nice, but the main reason we started checking the detail pages in the first place was to figure out how to get a price for each product. From the product listing, we could only scrape the min price, and remember—were building a Python app to track prices!
171+
Scraping the vendor's name is nice, but the main reason we started checking the detail pages in the first place was to figure out how to get a price for each product. From the product listing, we could only scrape the min price, and remember—we're building a Python app to track prices!
176172

177173
Looking at the [Sony XBR-950G BRAVIA](https://warehouse-theme-metal.myshopify.com/products/sony-xbr-65x950g-65-class-64-5-diag-bravia-4k-hdr-ultra-hd-tv), it's clear that the listing only shows min prices, because some products have variants, each with a different price. And different stock availability. And different SKUs…
178174

0 commit comments

Comments
 (0)