Difference between revisions of "Web scraping"
VKranendonk (talk | contribs) |
VKranendonk (talk | contribs) |
||
Line 48: | Line 48: | ||
<gallery> | <gallery> | ||
Web-scrape-selecting-elements-1.png|Selecting the first element | Web-scrape-selecting-elements-1.png|Selecting the first element | ||
Web-scrape-selecting-elements- | Web-scrape-selecting-elements-2.png|Selecting the second element - while holding shift | ||
Web-scrape-selecting-elements-3.png|Selecting the next element - while holding shift | |||
Web-scrape-selecting-elements-4.png|Selecting elements in second chapter - while holding shift | |||
</gallery> | </gallery> | ||
'''Step 7''' | '''Step 7''' |
Revision as of 09:32, 2 September 2022
Web scraping is used to scrape data such as text and images from websites. In this example we will scrape data from the Gutenberg website.
The purpose of web scraping is to transform web content into usable data for other programs or analysis. In this case we transform the following website into CSV data which can be opened in Microsoft Excel or Numbers.
Step 1:
We will use a browser extension called WebScraper.io. You can install the extension for Firefox or for for Chrome.
To learn about all of the functionality in the WebScraper.io extension you can watch the intro video.
Step 2:
After installing the extension you can navigate to Alice’s Adventures in Wonderland on the Gutenberg website.
Step 3:
Right click anywhere on the screen and click "inspect". This will open the inspector, a tool commonly used for debugging websites.
Step 4:
You should now have an extra tab called "Web Scraper Dev". Open this tab.
Step 5
Create a new sitemap. Call it for example "alice". The start url is the page you are currently on: https://www.gutenberg.org/files/11/11-h/11-h.htm
Step 6
Our goal will be to scrape each title and paragraph.
- Click on "Add new selector".
- Add an "Id" which makes sense, for example "content".
- Set "Type" from "Text" to "HTML". We do this because each paragraph can still have HTML inside it.
- Click "Select". You can now start selecting which elements you would like to scrape. Start with the title and then the paragraphs while holding "shift".
Step 7