Chapter 4. Writing Your First Web Scraper
Once you start web scraping, you start to appreciate all the little things that browsers do for you. The web, without its layers of HTML formatting, CSS styling, JavaScript execution, and image rendering, can look a little intimidating at first. In this chapter, we’ll begin to look at how to format and interpret this bare data without the help of a web browser.
This chapter starts with the basics of sending a GET request (a request to fetch, or “get,” the content of a web page) to a web server for a specific page, reading the HTML output from that page, and doing some simple data extraction in order to isolate the content you are looking for.
Installing and Using Jupyter
The code for this course can be found at https://github.com/REMitchell/python-scraping. In most cases, code samples are in the form of Jupyter Notebook files, with an .ipynb extension.
If you haven’t used them already, Jupyter Notebooks are an excellent way to organize and work with many small but related pieces of Python code, as shown in Figure 4-1.
Figure 4-1. A Jupyter Notebook running in the browser
Each piece of code is contained in a box called a cell. The code within each cell can be run by typing Shift + Enter, or by clicking the Run button at the top of the page.
Project Jupyter began as a spin-off project from the IPython (Interactive Python) project in 2014. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access