Skip to content

Commit b92dea2

Browse files
committed
fix: rewrite admonition and add some more guidance
1 parent 3729080 commit b92dea2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,24 @@ All is OK, mate
6969

7070
:::info Troubleshooting
7171

72-
If you see `ReferenceError: require is not defined in ES module scope, you can use import instead`, double check that in your `package.json` the type property is set to `module`.
72+
If you see errors or are otherwise unable to run the code above, it likely means your environment isn't set up correctly. Unfortunately, diagnosing the issue is out of scope for this course.
7373

74-
If you see other errors or for any other reason cannot run the code above, it means that your environment isn't set up correctly. We're sorry, but figuring out the issue is out of scope of this course.
74+
75+
If you see errors or for any other reason cannot run the code above, it means that your environment isn't set up correctly. We're sorry, but figuring out the issue is out of scope of this course.
76+
77+
Make sure that in your `package.json` the type property is set to `module`, otherwise you'll get the following warning:
78+
79+
```text
80+
[MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/.../product-scraper/index.js is not specified and it doesn't parse as CommonJS.
81+
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
82+
To eliminate this warning, add "type": "module" to /Users/.../product-scraper/package.json.
83+
```
84+
85+
In older versions of Node.js, you may even encounter this error:
86+
87+
```text
88+
SyntaxError: Cannot use import statement outside a module
89+
```
7590

7691
:::
7792

@@ -85,6 +100,12 @@ const response = await fetch(url);
85100
console.log(await response.text());
86101
```
87102

103+
:::tip Asynchronous flow
104+
105+
First time you see `await`? It's a modern syntax for working with promises. See the [JavaScript Asynchronous Programming and Callbacks](https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks) and [Discover Promises in Node.js](https://nodejs.org/en/learn/asynchronous-work/discover-promises-in-nodejs) tutorials in the official Node.js documentation for more.
106+
107+
:::
108+
88109
If we run the program now, it should print the downloaded HTML:
89110

90111
```text
@@ -225,7 +246,7 @@ https://warehouse-theme-metal.myshopify.com/collections/sales
225246

226247
### Download an image as a file
227248

228-
Download a product image, then save it on your disk as a file. While HTML is _textual_ content, images are _binary_. You may want to scan through the [Fetch API documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#reading_the_response_body) for guidance. Especially check `Response.arrayBuffer()`. You can use this URL pointing to an image of a TV:
249+
Download a product image, then save it on your disk as a file. While HTML is _textual_ content, images are _binary_. You may want to scan through the [Fetch API documentation](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#reading_the_response_body) and the [Writing files with Node.js](https://nodejs.org/en/learn/manipulating-files/writing-files-with-nodejs) tutorial for guidance. Especially check `Response.arrayBuffer()`. You can use this URL pointing to an image of a TV:
229250

230251
```text
231252
https://warehouse-theme-metal.myshopify.com/cdn/shop/products/sonyxbr55front_f72cc8ff-fcd6-4141-b9cc-e1320f867785.jpg

0 commit comments

Comments
 (0)