

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Main
incomplete
2: Get HTML
incomplete
3: Adding Recursion
incomplete
This lesson's interactive features are locked, please to keep using them
This is going to be the largest step so far, and will require some "figuring things out on your own"... you got this.
def crawl_page(base_url, current_url=None, page_data=None):
base_url is the root URL of the website we're crawlingcurrent_url is the current URL we're crawlingIn the first call to crawl_page() current_url is a copy of base_url, but as we make further HTTP requests to all the URLs we find on the base_url, the current_url value will change while the base stays the same.
The page_data dictionary stores all the rich data we've extracted from each page, keyed by normalized URL. This function should continue to pass the same dictionary to itself.
Here's my pseudocode:
current_url is on the same domain as the base_url. If it's not, just return. We don't want to crawl the entire internet, just the domain in question.current_url.page_data dictionary. If we have, just return - we don't want to crawl the same page twice.extract_page_data() to get the rich data from this page and add it to the page_data dictionary using the normalized URL as the key.Be careful testing this! Be sure to add print statements so you can see what your crawler is doing, and kill it with Ctrl+C if it's stuck in a loop. If you make too many spammy requests to a website (including the sandbox) you could get your IP address blocked.
uv run main.py https://learnwebscraping.dev/practice/ecommerce/