Book Image

Go Web Scraping Quick Start Guide

By : Vincent Smith
Book Image

Go Web Scraping Quick Start Guide

By: Vincent Smith

Overview of this book

Web scraping is the process of extracting information from the web using various tools that perform scraping and crawling. Go is emerging as the language of choice for scraping using a variety of libraries. This book will quickly explain to you, how to scrape data data from various websites using Go libraries such as Colly and Goquery. The book starts with an introduction to the use cases of building a web scraper and the main features of the Go programming language, along with setting up a Go environment. It then moves on to HTTP requests and responses and talks about how Go handles them. You will also learn about a number of basic web scraping etiquettes. You will be taught how to navigate through a website, using a breadth-first and then a depth-first search, as well as find and follow links. You will get to know about the ways to track history in order to avoid loops and to protect your web scraper using proxies. Finally the book will cover the Go concurrency model, and how to run scrapers in parallel, along with large-scale distributed web scraping.
Table of Contents (10 chapters)

Searching using Cascading Style Sheets selectors

You can see how using a structured query language makes searching for, and retrieving, information much easier than basic string searches. However, XPath was designed for generic XML documents, not HTML. There is another structured query language that is made specifically for HTML. Cascading Style Sheets (CSS) were created to provide a way to add stylistic elements to HTML pages. In a CSS file, you would define a path to an element or multiple elements, and what describes the appearance. The definitions for the path to the element are called CSS selectors and are written specifically for HTML documents.

CSS selectors understand common attributes that we could use in searching HTML documents. In the previous XPath examples, we often used a query such as div[@class="some-class"] in order to search for elements with the class...