Introduction to SQLite
The central relationship is simple: spider.py performs the crawl, while spider.sqlite stores the pages and connections found during that crawl.
A Crawl That Remembers
A web spider does more than visit one page. The spider.py script crawls websites, records links, and discovers new content by extracting links from the HTML of pages it visits. The spider.sqlite file provides persistent storage for the crawled pages and the connections between them.
The central relationship is simple: spider.py performs the crawl, while spider.sqlite stores the pages and connections found during that crawl.
Following the Crawl
The crawl begins with spider.py. As the script visits a page, it examines that page's HTML. Links found in the HTML become discoveries that can lead the spider toward additional pages. This link-extraction step is the mechanism that allows the crawl to find new content rather than stopping at the first page.
Tracing a Link Discovery
Imagine that spider.py visits a page whose HTML contains links to two other pages. What happens in the crawl?
- 1Visit
spider.pyvisits the page as part of the website crawl. - 2Inspect
The spider examines the HTML of the visited page.
- 3Extract
The spider discovers the links contained in that HTML.
- 4Continue
The discovered links provide paths toward additional pages and new content.
The crawl advances because links extracted from a visited page identify further content to crawl.
What spider.sqlite Stores
spider.sqlite is the database where all crawled pages and their connections are stored. The database therefore records more than an isolated list of pages: it also stores how those pages are connected through discovered links.
Resetting the Crawl
spider.sqlite contains recorded crawled pages and their connections.
The existing crawl data remains stored in spider.sqlite.
spider.sqlite has been deleted.
The stored crawl record has been removed, so the crawl can be restarted.
To restart a crawl, delete the spider.sqlite file. Deleting this file removes the stored record of the crawled pages and their connections, which resets the persistent crawl state.
Common mistake Assuming that changing spider.py alone resets the crawl.
What it looks likeThe script is changed, but spider.sqlite is left in place.
Why it failsThe crawl information is stored in
spider.sqlite, so the existing database file still contains the recorded pages and connections.Do this insteadDelete spider.sqlite when the goal is to restart the crawl.
Common mistake Treating spider.sqlite as the crawler itself.
What it looks likeDescribing the database file as if it visits websites and extracts links.
Why it failsspider.pyis the script used to crawl websites and record links.spider.sqliteis where the crawled pages and their connections are stored.Do this insteadAssign crawling and link recording to spider.py, and assign persistent storage to spider.sqlite.
Common mistake Ignoring the HTML link-extraction step.
What it looks likeThinking the spider discovers new content without examining visited pages.
Why it failsThe spider discovers new content by extracting links from the HTML of visited pages.
Do this insteadTrace the crawl through a visited page's HTML and the links found there.
Check Your Understanding
A spider visits a page and finds links in its HTML. Explain which component performs the crawl, which component stores the crawled pages and connections, and what must be deleted to restart the crawl.
Hints
- Separate the active script from the stored database file.
- Use the sequence visited page, HTML, extracted links, and additional content.
- The reset action concerns the file that stores crawl data.
What do you think happens?
If spider.sqlite is not deleted, has the crawl's stored state been reset?
Reveal answer
No
The stored crawl data remains in spider.sqlite. To restart the crawl, the spider.sqlite file must be deleted.
Key Takeaways
- 1
spider.pyis the script that crawls websites and records links. - 2The spider discovers new content by extracting links from the HTML of visited pages.
- 3
spider.sqlitestores all crawled pages and their connections. - 4Deleting
spider.sqliteresets the stored crawl state and allows the crawl to restart.
At a glance
- A web spider advances by visiting pages and extracting links from their HTML.
spider.pyperforms the crawling and records discovered links.spider.sqlitestores crawled pages and the connections between them.- Deleting
spider.sqliteis the required reset action for restarting the crawl.