-
Notifications
You must be signed in to change notification settings - Fork 129
feat: update the scraping variants lesson of the JS2 course to be about JavaScript #1846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Preview for this PR was built for commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
a083a57
to
0d22cf5
Compare
Preview for this PR was built for commit |
Thanks! I noticed there was a conflict with master now, so I resolved it. I'll wait for @gullmar to check code before merging. |
@cursor review |
@cursor review |
Preview for this PR was built for commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
Comment @cursor review
or bugbot run
to trigger another review on this PR
sources/academy/webscraping/scraping_basics_javascript2/11_scraping_variants.md
Outdated
Show resolved
Hide resolved
item = parse_product(product, listing_url) | ||
product_soup = download(item["url"]) | ||
vendor = product_soup.select_one(".product-meta__vendor").text.strip() | ||
const $promises = $(".product-item").map(async (i, element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const $promises = $(".product-item").map(async (i, element) => { | |
const promises = $(".product-item").toArray().map(async (element) => { |
|
||
return item; | ||
}); | ||
const data = await Promise.all($promises.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const data = await Promise.all($promises.get()); | |
const data = await Promise.all(promises); |
const $ = await download(listingURL); | ||
|
||
Python dictionaries are mutable, so if we assigned the variant with `item["variant_name"] = ...`, we'd always overwrite the values. Instead of saving an item for each variant, we'd end up with the last variant repeated several times. To avoid this, we create a new dictionary for each variant and merge it with the `item` data before adding it to `data`. If we don't find any variants, we add the `item` as is, leaving the `variant_name` key empty. | ||
const $promises = $(".product-item").map(async (i, element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const $promises = $(".product-item").map(async (i, element) => { | |
const promises = $(".product-item").toArray().map(async (element) => { |
// highlight-end | ||
}); | ||
// highlight-start | ||
const itemLists = await Promise.all($promises.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const itemLists = await Promise.all($promises.get()); | |
const itemLists = await Promise.all(promises); |
} | ||
return [{ variantName: null, ...item }]; | ||
}); | ||
const itemLists = await Promise.all($promises.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const itemLists = await Promise.all($promises.get()); | |
const itemLists = await Promise.all(promises); |
const listingURL = "https://www.npmjs.com/search?page=0&q=keywords%3Allm&sortBy=dependent_count"; | ||
const $ = await download(listingURL); | ||
|
||
const $promises = $("section").map(async (i, element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const $promises = $("section").map(async (i, element) => { | |
const promises = $("section").toArray().map(async (element) => { |
return { name, url, description, dependents, downloads }; | ||
}); | ||
|
||
const data = await Promise.all($promises.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const data = await Promise.all($promises.get()); | |
const data = await Promise.all(promises); |
const listingURL = "https://edition.cnn.com/sport"; | ||
const $ = await download(listingURL); | ||
|
||
const $promises = $(".layout__main .card").map(async (i, element) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const $promises = $(".layout__main .card").map(async (i, element) => { | |
const promises = $(".layout__main .card").toArray().map(async (element) => { |
return { url: articleURL, length: content.length }; | ||
}); | ||
|
||
const data = await Promise.all($promises.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const data = await Promise.all($promises.get()); | |
const data = await Promise.all(promises); |
Co-authored-by: gullmar <gullmar@mailbox.org>
Preview for this PR was built for commit |
Thank you! 🙇♂️ |
…ut JavaScript (apify#1846) Part of apify#1584 ----⚠️ 🐍 This PR contains also a small change to the Python course, to keep the lessons consistent and synced. --------- Co-authored-by: gullmar <gullmar@mailbox.org>
Part of #1584