Scrapling Tutorial: Scrape a Whole Website with Python

By Beau Johnson··9 min read

Quick answer

I use Scrapling 0.5.1, an open source Python scraping framework, to crawl a 1,000 book practice store in 18 seconds on my machine. Then I fix the places where it loses data: a list bug, pause and resume, site redesigns, and JavaScript pages.

In this video I walk through Scrapling, an open source Python web scraping framework, from a clean install to a finished project. I point one Python file at a practice book store, pull 1,000 books across 1,050 pages in 18 seconds on my machine, and turn the results into a deals dashboard. It's for anyone who has copied prices into a spreadsheet by hand, or who wants an AI agent to read a site that has no API.

What I cover in this video

  • 0:45 What Scrapling is, the three jobs it does, and the three ways you can drive it
  • 4:36 The virtual environment, the install, and why I pin version 0.5.1
  • 6:07 The first scrape from the terminal with no code, then five lines of Python
  • 8:24 The spider file, top to bottom
  • 9:54 The first run that returns zero books, and the one word fix
  • 10:40 Pause and resume, and how the first 276 books went missing
  • 13:41 Adaptive selectors tested against a redesign I made myself
  • 18:16 The catch: robots.txt, the README pitch, disk size, and the speed claims

Setting up Scrapling 0.5.1

Scrapling needs Python 3.10 or newer, and the package says it supports 3.10 through 3.13. The Python that ships on a Mac is 3.9.6, which is too old. If yours says 3.9, run brew install python@3.13 and use that Python for the next command. Everything ran fine on 3.14 in my test, but 3.13 is what the package says it supports.

python3 --version
python3 -m venv ~/scrapling-env
source ~/scrapling-env/bin/activate
pip install "scrapling[all]==0.5.1"
scrapling install
python -m patchright install chromium

The quotes on the pip line matter because the Mac terminal chokes on square brackets without them. The all part pulls in the browser fetcher, the interactive shell, and the MCP server. Without it you only get the parser. I pin the version on purpose. Version 0.5 changed a lot, and a class called DynamicFetcher is gone. If an older tutorial or an AI answer tells you to use it, that's from before the rewrite and it won't work.

Watch the last two lines. scrapling install finishes with no errors, so it looks done, but it doesn't download everything. The patchright command covers the gap, and I show the crash you get without it later in the video.

The first scrape and the spider

The store is books.toscrape.com, a practice site built for this. The page says, "We love being scraped." You can scrape it without writing any code:

scrapling extract get "https://books.toscrape.com/" books.md -s "article.product_pod"

Without the -s selector you get the whole page, category menu included. With it, the file is only the book cards. To find a selector on any site, right click the thing you want in Chrome, hit Inspect, and look at the tag around it.

The Python version is five lines. It imports the Fetcher, grabs the front page, loops through the first five book cards, and prints the price and the link's title attribute. I use the title attribute because the link text on this store gets cut off.

One page is 20 books. The store has 50 listing pages plus a page for every book, so the real build is a spider in books_spider.py. It starts at the first catalog page, works on eight pages at a time (the default is four), and sets robots_txt_obey = True. One function runs on every listing page, follows each book link, then follows the next button. A second function runs on each book page and yields one row: title, price, rating, stock, category, and address. The full files are in the agent kit, which you can hand to Claude Code to build the whole project.

Two bugs that cost you data

My first run made 1,050 requests, every one came back 200, and the last line said zero books. Scrolling up showed 1,000 errors. The cause: css() hands you a list of matches even when there's only one, and get_all_text only works on a single element. The fix is one word. Add .first before getting the text. The next run returned 1,000 books in 18 seconds with zero failed.

The second bug is easier to miss. Because the spider has a crawl folder, Ctrl+C pauses it and saves a checkpoint, and the same command resumes it. I stopped at 276 books, ran it again, and it finished the other 724. Then I counted the CSV and it held only those 724. The checkpoint saves the to-do list and the pages already visited. It does not save the books, and the CSV export writes a brand new file on every run.

The fix is four lines plus import json. Scrapling has a hook called on_scraped_item that runs every time a book comes in. Inside it I open a file in append mode, write that one book as a line, and return the item. I tested it the same way: 308 books before Ctrl+C, 692 after the resume, 1,000 lines in the file.

From there, report.py is plain Python with no Scrapling in it. It reads that file, keeps one row per book address, and writes deals.html: 1,000 books across 50 categories, with 42 five star books under £20.

Redesigns, JavaScript pages, and the catch

When a site redesigns, your selector finds nothing and you get an empty spreadsheet with no error. I tested adaptive selectors by saving the store's first page and making my own redesign, where the price moved to a different tag with a different class. With adaptive turned on and auto save set on the selector, the first run saved a fingerprint of the first match. After the swap, the normal selector found zero prices and the adaptive one found the price in its new spot. A find similar call then brought back all 20.

This is plain similarity scoring with no AI involved, and it has limits:

  • It only saves the first match.
  • It only kicks in when your selector finds nothing at all.
  • Its database lives inside your virtual environment by default, so deleting that folder wipes it.
  • It can guess wrong with no warning, so check the first run after a site changes.

For pages that only load with JavaScript, the normal Fetcher got zero quotes from the practice page at quotes.toscrape.com/js. StealthyFetcher opens a real Chrome in the background, but it crashed with Executable doesn't exist until I ran python -m patchright install chromium. After that it returned 10 quotes.

A few catches before you run this on a real site. Only the Spider reads robots.txt, and only when you turn it on. The Fetcher, the StealthyFetcher, the extract command, and the MCP server never look at it. The BSD license covers Scrapling's code and gives you no permission to scrape anybody's site, so read the terms yourself. The spider doesn't slow down on its own either, so set a download delay of a second or two and drop the concurrent requests. The README talks about getting past Cloudflare, but the maintainer has said access to some protected sites is not guaranteed. And the README's benchmark numbers are the author's own. An independent rerun found it basically tied with Parsel, the parser Scrapy uses.

Key takeaways

  • Pin scrapling[all]==0.5.1 and run the extra patchright command, or browser pages crash.
  • css() returns a list. Use .first before get_all_text or you get zero rows and an error for every page.
  • Resume saves the to-do list, not your data. Append each item to a file in on_scraped_item.
  • Adaptive selectors can relocate an element after a redesign, but they can guess wrong, so check the first run after a site changes.
  • Read a site's terms and robots.txt yourself, and add a download delay on real sites.

FAQ

What Python version does Scrapling need?

Scrapling 0.5.1 declares support for Python 3.10 through 3.13. The Python built into a Mac is 3.9.6, which is too old, so I install a newer one with Homebrew using brew install python@3.13.

Why does StealthyFetcher crash after running scrapling install?

The scrapling install command finishes with no errors but doesn't download the Chrome build that StealthyFetcher needs, so it fails with an Executable doesn't exist error. Running python -m patchright install chromium fixed it in my test.

Does Scrapling save my scraped data when I pause and resume a spider?

No. The checkpoint saves the to-do list and the pages already visited, not the items, and the CSV export writes a new file every run. Append each item to a file inside the on_scraped_item hook so nothing gets wiped.

Does Scrapling obey robots.txt?

Only the Spider reads robots.txt, and only when you set robots_txt_obey = True, which is off by default. The Fetcher, StealthyFetcher, the extract command, and the MCP server never check it, so read a site's terms and robots file yourself.

Chapters

  1. 0:001,000 books, one Python file
  2. 0:38What Scrapling is
  3. 2:30How it works: fetch, parse, select, crawl
  4. 4:06Module 1: Setup (Step 1: check your Python)
  5. 4:44Step 2: A virtual environment and the install
  6. 5:42Step 3: scrapling install
  7. 6:00Module 2: First run (Step 4: the terminal way)
  8. 7:10Step 5: Five lines of Python
  9. 8:13Module 3: The build (Step 6: the spider)
  10. 9:47Step 7: Run it (and the one word fix)
  11. 11:04Step 8: Pause and resume (and the lost books)
  12. 12:54Step 9: The dashboard
  13. 13:57Module 4: Make it hard to break (Step 10: adaptive selectors)
  14. 16:26Step 11: JavaScript pages and the browser fix
  15. 18:04Module 5: The catch
  16. 19:54Recap and the agent kit

Transcript

Read the full transcript

0:00With Scrappling, I just pointed one Python file at an entire online store. 1,000 books, 18 seconds on my machine. Then I killed it mid-run and it picked up where it stopped. Then I redesigned the store and it still found the prices. But the speed is the boring part. What matters is when it breaks because that's where you lose data without knowing it. So in this video, five modules. setup, your first scrape, the real build, making it hard to break, and the catch. By the end, this deals dashboard runs on your machine. I ran every command, mistakes included. Let's jump right into it. So, the repo is called Scrappling. It's on GitHub under D4 Vinci. It's built by a developer in Egypt named

0:45Kareem Shawer, and it's sitting at about 104,000 stars right now. It started just over 2 years ago and the newest version 0.5.1 came out on November 4th. You might remember it from our weekly roundup on November 9th where it was one of the top trending repos. So what is it exactly? It's a web scraping framework for Python. You give it a web page, it grabs the page, and then you point at the parts you want, like the prices or the titles, and it hands them back to you as clean data. That's it. That's the whole idea. Now, here's why it's blowing up. It does three jobs that used to take three different tools. It can grab a page the fast way, like a normal request. It can open a real browser for

1:30pages that only show up after JavaScript runs. And it has a full crawler built in, called a spider, that walks a whole website for you, a bunch of pages at a time, and can pause and resume. And you can drive it three ways. from the terminal with one command, from Python, which is what we're doing today, or through an MCP server so your coding agent can use it as a tool. So, who is this for? If you've ever copied prices into a spreadsheet by hand, tracked listings, or wanted your agent to read a site that has no API, this is for you. Here's how I'd use it in my resale business. Point it at a shop's listings, pull every price and size, and check them every morning instead of scrolling. And the license is BSD, so you can use it in your own projects. Easy Flip got

2:17460,000 views in 11 days. Nightcrew made one new short every day and posted it to four platforms. The best one hit 155,000. Want that for your business? Nightcrew.studio. So, how does this thing actually work? Every scraper does four jobs, and Scrappling is no different. First, it fetches. Scrapplings fetcher sends a normal web request the same way your browser asks a site for a page and it sends it with browser-like headers so it looks like a regular visitor. One fun detail in every one of our runs, the log shows it says it came from a Google search. Second, it parses the page comes back as a big wall of HTML and Scrappling turns that into a tree it can search. Third, it selects. You hand it a

3:04CSS selector, which is just an address for a part of the page, like every article with the class product pod or the paragraph with the class price color, and it gives you back exactly those pieces. And fourth, for a whole site, the spider takes over. It keeps a to-do list of pages. It runs eight of them at the same time in our build. It skips anything it already visited, and every time you stop it, it writes the to-do list to a file. So, the next run starts from that list instead of from the top. Then, there's one more trick we'll get to in module four called adaptive. When a site redesigns and your selector stops matching, Scrappling can go looking for the thing you meant by what it looked like. We're going to break a page on purpose and watch it work. And the store we're scraping today is books.tscrape.com.

3:51It's a practice store run by Zeit, built for exactly this. The page literally says, "We love being scraped." The prices and ratings are made up and that's fine. It's a safe place to learn and the same code works on real sites as long as the site lets you in. Okay, module one, the setup. Three steps and one of them looks done when it isn't. Step one, check your Python. Scrappling needs Python 3.10 or newer. And here's the first trap. The Python that ships on a Mac is 3.9.6. You can see it right there. Too old. So, I'm using a newer one from Homebrew, 3.14.8. So, if yours says 3.9, run brew install Python at 3.13 and use Python 3.13 for

4:36the next command. Everything in this video ran fine on 314 in my test, but 313 is what the package says it supports. Step two, a virtual environment and the install. A virtual environment is just a folder that keeps this project's packages away from everything else on your computer. So, Python 3-MV envir to turn it on. You can see the prompt changes. Then, pip install in quotes because the Mac terminal chokes on square brackets without them. Scrappling all in square brackets equals 0.5.1. The all part pulls in the extras, the browser fetcher, the interactive shell, and the MCP server. Without it, you only get the parser. And I'm pinning the

5:21version on purpose. Version 0.5 came out in October and it changed a lot. A class called dynamic fetcher is gone, for example. So if you find an older tutorial or an AI answer telling you to use dynamic fetcher, that's from before the rewrite. It won't work. Then scrappling- version 0.5.1. Good. Step three, scrappling install. This is supposed to download the Chrome that Scrappling drives for the browser pages. It took 8.6 6 seconds on my connection and it finishes with no errors. So, it looks done, but it doesn't actually get everything. We'll find out why in module 4. And it's going to crash on us. So, module two, your first scrape. And we're going to do it twice. Once without writing any code and

6:07once with five lines of Python. Step four, the terminal way. Make a folder called book deals and go into it. Then scrappling extract get the store's address and a file name page.md. It fetches the page status 200 and saves it as markdown which is plain text that's easy to read. So let's look at it and you can see the problem. The first 24 lines are the title. We love being scraped and then a whole menu of categories. Travel, mystery, historical fiction. That's the whole page, not just the books. So, same command with a new file name, books.m MD. And now we add - S and a CSS selector. Article.product_pod. That's the address of each book card on

6:52this store. And now the file is only the books. A light in the attic. 5177 in stock. Tipping the velvet. Clean. How did I know that selector? Rightclick a book in Chrome, hit inspect, and look at the tag around it. That's the whole trick, and you'll use it for every site. Step five, the Python way. I made a file called first.py and it's five lines. Line one imports the fetcher. Line three grabs the store's front page. Line four loops through the first five book cards. And line five prints two things from each card. The text inside the price and the title attribute of the link. Now, why the title attribute and not the link text? Because on this store, the link text gets cut off. A light [snorts] in the attic shows up as a light in the dot

7:38dot dot. The full title lives in the title attribute. These little things are most of what scraping actually is. So, Python first.py. And there it is. 5177, A Light in the Attic. 5374, Tipping the Velvet, Sumision, Sharp Objects, Sapiens. Five books, five prices. And that's one page. The store has 50 pages. And every single book has its own page with the category and how many are in stock. That's 1,50 pages. Nobody is copying that by hand. So now we build the real thing. Module three, the build. This is the spine of the whole video. So let's slow down. Step six, the spider. Here's the file books spider.py. And

8:24I'll walk you through it top to bottom. At the top, we import spider from scrappling.spiders and a little dictionary that turns the star rating words 1 through 5 into numbers. The store writes ratings as a word in a class name. So we translate it. Then the class it needs a name books. Start URLs is the first catalog page. Concurrent requests is eight. So it works on eight pages at a time. The default is four. And robots_txt obey equals true. That tells the spider to read the site's robots file and skip anything it's told to skip. This store doesn't have one. You can see the 404 right there. So everything's allowed, but I turn it on anyway. More on that in the catch. Then two functions. Parse

9:09runs on every listing page. For each book card, it follows the link to that book's own page and hands it to the second function. And then if there's a next button, it follows that too. That's the whole crawl. 20 books a page, then next, then next until there is no next. The second function, parse book, runs on every book's page and yields one row. the title, the price as a number, the rating as a number, how many are in stock, the category from the little breadcrumb at the top, and the address. And at the bottom, we start the spider with a crawl folder called crawl state. Save everything to books.cssv, and print how many books we got and how long it took. Step seven, run it. Python bookspider.py. And look at that, the log is flying. 18

9:54seconds, 1,50 requests. Every single one came back 200. And then the last line says zero books. Scroll up and there are 1,000 errors. So, what went wrong? The error says a selector's object has no attribute get all text. And this is the kind of bug you'll hit on day one. When you ask for p.availability, scrappling hands you a list of matches, even if there's only one. And get all text only works on one element, not on a list. So, the fix is one word. Add dot first. Give me the first match, then get its text. Run it again. 1,00 books in 18 seconds. About 59 pages a second. Zero failed. Let's look at the file. Title, price, rating, in stock, category, address. A

10:40light in the attic, 5177, three stars, 22 in stock, poetry, 1,01 lines, so 1,000 books plus the header. That's a whole store. And this is where most tutorials stop. But real crawls don't run on a practice store in 18 seconds. They run for an hour and then your Wi-Fi drops or you close your laptop. So what happens then? Step eight, pause and resume. Because we gave the spider a crawl folder, you can just hit C. Watch. I start it and 6 seconds in, C. It says pause requested. It lets the pages that were already loading finish and then checkpoint saved. 276 books so far. And in the crawl state folder, there's a

11:25file called checkpoint.pkl. That's the to-do list. So run the exact same command again. Checkpoint loaded. Resuming from checkpoint. It skips everything it already visited and finishes the rest. 724 more books in 13 seconds. Perfect, right? Let's count the file. 725 lines. So 724 books. And the first 276 are gone. The reason is simple once you see it. The checkpoint saves the to-do list and the pages it already saw. It does not save the books. And to CSV writes a brand new file every run with only what that run scraped. So the resume worked perfectly and our data still got wiped. This is the bit that's easy to miss and it's exactly the kind of thing that bites you on the long

12:11jobs, the ones you actually care about. The fix is four lines plus import JSON at the top. Scrappling gives you a hook called onscraped item and it runs every time a book comes in. So inside it we open books.jsl in append mode and write that one book as a line. Append means add to the end never wipe. Then we return the item so everything else still works. Test it the same way. Fresh start. Ctrl C at 6 seconds. 308 books and the file has 308 lines. Run it again. It resumes 692 more. And now count the lines. 1,000. Every book across two runs. That's a scraper you can trust with an hour-ong job. Step nine, the dashboard. I wrote a second

12:56small file, report.py. It's plain Python. No scrappling in it at all. It reads books.jsl, keeps one row per book address in case anything shows up twice, and writes an HTML page called deals.html. Pythonreport.py. 1,000 books, 42 five-star deals under 20. Let's open it. And there it is. Book deals. 1,000 books across 50 categories. An average price of £35.7 and 42 five-star books under 20. Then the biggest categories with default at the top, £152 books. And yes, add a comment is a real category on this store. It's a practice site. Then the deals table. Cheapest first. An

13:41abundance of Catherine's five stars, 10 pounds flat, and the cheapest book in every single category at the bottom. So, that's the whole build. One spider, one report, a URL to a dashboard. But right now, it only works as long as the store never changes. Module four, making it hard to break. Two things that will happen to you the first week you scrape a real site. The site changes its design, and the site only shows up after JavaScript runs. Step 10, adaptive selectors. Here's the problem. Your scraper works today. Next month, the store redesigns. The price is now in a different tag with a different class. And your selector finds nothing. No error. Just zero prices and an empty spreadsheet. So, I tested this for real.

14:28I saved the store's first page and then I made my own redesign of it. Both pages and the little server command are in the agent kit. So, you can run this exact test. The book card is now a div called bookcard instead of an article. And the price moved from a paragraph called price color into a span called amount. You can see both lines right here. Same price, totally different address. I serve the original page on my own machine and I run adaptive.py with save. You need two things. Fetcher.configure adaptive equals true and autosave equals true on the selector. Saved 20 prices. First one 5177. Now I swap in the redesign. Same address, new page. Run it with check. The normal selector, zero prices.

15:14Exactly what would happen to you. But the adaptive selector found it. 5177. And it tells us it's now inside a span. Then one more call. Find similar. Grabs every element that looks like that one. And we're back to 20 prices. So how does it actually know? When you save, it writes down a fingerprint of the first match. Its tag, its attributes, its text, its parent, its neighbors. It keeps that in a small database file. Then, when your selector comes back empty, it scores every element on the new page against that fingerprint and takes the best one as long as it scores at least 40%. It's not AI, it's plain similarity scoring. And four honest limits. It only saves the first match, which is why we need find similar to get

15:59the rest. It only kicks in when your selector finds nothing at all. And that database lives inside your virtual environment by default. So if you delete the folder, it forgets everything. You can point it somewhere else with storage args. And it can guess wrong. If something on the new page looks more like your old price than the real price does, it grabs that with no warning. There's an open issue on the repo about exactly that. So check the first run after a site changes. Step 11, JavaScript pages. Remember module one? I said scrappling install doesn't get everything. Here's where it bites. The page is quotes.crape.com/js. It's a practice page where the quotes only show up after JavaScript runs. My file tries it both ways. First, the

16:45normal fetcher, zero quotes, because the raw page has no quotes in it yet. The browser builds them after it loads. So the second half uses stealthy fetcher which opens a real Chrome in the background, lets the page finish and then reads it and it crashes. Executable doesn't exist. Looks like Playright was just installed. So here's what's going on. Scrappling installs two browser libraries, Playright and Patch. Scrappling installed downloaded Playright's Chrome build 1255, but Stealthy Fetcher runs on Patchrite and Patchright wants a different build, 1248. Nobody downloaded that one. There's an open pull request about exactly this on the repo number 585 and it's still open today. The fix is one command. Python-m patchright install

17:31chromium. That took 6.7 seconds on my connection. Run the file again. Fetcher zero quotes. Stealthy fetcher 10 quotes. The world as we have created it is a process of our thinking. There it is. And if you'd rather have Claude Code do the fetching for you, Scrapplings's MCP server gives your agent 17 tools for grabbing pages and driving a browser. I already made a step-by-step lesson inside Shipping School Premium where Claude Code uses that MCP server to page through this same store on its own, and I'll put the link down below. Module five, the catch. Before you go run this on every site you can think of, there are a few catches, and I'd rather you hear them from me than find them the hard way. First, the robots file and the

18:16terms. Only the spider reads a site's robots file, and only when you set robots txt obey to true. It's off by default. The fetcher, the stealthy fetcher, the extract command, and the MCP server never look at it. So, before you point this at a real site, read its terms and its robots file yourself. The BSD license covers Scrapplings's code. It doesn't give you permission to scrape anybody's site, and the Spider doesn't slow down on its own. The default is four pages at a time with no weight, and I ran eight, which is fine on a practice store that wants it. On a real site, set download delay to a second or two and drop the concurrent requests. Second, the pitch. The readme talks about getting past Cloudflare, and a big chunk of it is ads for proxy and capture

19:02solving services. The maintainer has also said access to some protected sites is not guaranteed. So treat it as a great scraper, not a skeleton key. Third, the size. The virtual environment is 448 megabytes and the browsers are another 1.1 GB. And like we saw, you need that extra patch command or the browser pages crash. Fourth, the version stuff. Python 310 through 313 is what it says it supports. and anything written before version 0.5 like dynamic fetcher is out ofd. And last, the speed claims. The readme has a benchmark where it parses about 785 times faster than beautiful soup. Those are the author's own numbers and an independent rerun found it basically tied with parcel the

19:48parser scrapey uses. Our 18 seconds is one practice store on one night. Take that for what you will. So that's the whole course. You set it up. You scraped your first page two ways. You built a spider that reads a whole store and survives being stopped halfway. You turned it into a dashboard and you made it hold up when a site redesigns or runs on JavaScript. And I put the whole project into one agent kit. Every file, every command, and every fix from this video, hand it to Claude Code and it builds book deals for you step by step. The link is down below. Okay, last thing. What's the first site you'd point this at and what would you pull off it? Write it under this video. I want to know. Give this one a like if it saved you a weekend of copy and paste. That's how I know to make more of these. Have a

20:34blessed day.

Ready to start building with AI?

Join the Shipping Skool community free. Paid members get live bootcamp calls every week and weekly-updated courses.

Join Shipping Skool

Keep reading