Book description
Untangle your web scraping complexities and access web data with ease using Python scripts
About This Book
- Hands-on recipes for advancing your web scraping skills to expert level.
- One-Stop Solution Guide to address complex and challenging web scraping tasks using Python.
- Understand the web page structure and collect meaningful data from the website with ease
Who This Book Is For
This book is ideal for Python programmers, web administrators, security professionals or someone who wants to perform web analytics would find this book relevant and useful. Familiarity with Python and basic understanding of web scraping would be useful to take full advantage of this book.
What You Will Learn
- Use a wide variety of tools to scrape any website and data—including BeautifulSoup, Scrapy, Selenium, and many more
- Master expression languages such as XPath, CSS, and regular expressions to extract web data
- Deal with scraping traps such as hidden form fields, throttling, pagination, and different status codes
- Build robust scraping pipelines with SQS and RabbitMQ
- Scrape assets such as images media and know what to do when Scraper fails to run
- Explore ETL techniques of build a customized crawler, parser, and convert structured and unstructured data from websites
- Deploy and run your scraper-as-aservice in AWS Elastic Container Service
In Detail
Python Web Scraping Cookbook is a solution-focused book that will teach you techniques to develop high-performance scrapers and deal with crawlers, sitemaps, forms automation,
Ajax-based sites, caches, and more.You'll explore a number of real-world scenarios where every part of the development/product life cycle will be fully covered. You will not only develop the skills to design and develop reliable, performance data flows, but also deploy your codebase to an AWS. If you are involved in software engineering, product development, or data mining (or are interested in building data-driven products), you will find this book useful as each recipe has a clear purpose and objective.
Right from extracting data from the websites to writing a sophisticated web crawler, the book's independent recipes will be a godsend on the job. This book covers Python libraries, requests, and BeautifulSoup. You will learn about crawling, web spidering, working with AJAX websites, paginated items, and more. You will also learn to tackle problems such as 403 errors, working with proxy, scraping images, LXML, and more.
By the end of this book, you will be able to scrape websites more efficiently and to be able to deploy and operate your scraper in the cloud.
Style and approach
This book is a rich collection of recipes that will come in handy when you are scraping a website using Python.
Addressing your common and not-so-common pain points while scraping website, this is a book that you must have on the shelf.
Table of contents
- Title Page
- Copyright and Credits
- Contributors
- Packt Upsell
- Preface
- Getting Started with Scraping
- Data Acquisition and Extraction
- Processing Data
-
Working with Images, Audio, and other Assets
- Introduction
- Downloading media content from the web
-  Parsing a URL with urllib to get the filename
- Determining the type of content for a URL 
- Determining the file extension from a content type
- Downloading and saving images to the local file system
- Downloading and saving images to S3
-  Generating thumbnails for images
- Taking a screenshot of a website
- Taking a screenshot of a website with an external service
- Performing OCR on an image with pytesseract
- Creating a Video Thumbnail
- Ripping an MP4 video to an MP3
- Scraping - Code of Conduct
-
Scraping Challenges and Solutions
- Introduction
- Retrying failed page downloads
- Supporting page redirects
- Waiting for content to be available in Selenium
- Limiting crawling to a single domain
- Processing infinitely scrolling pages
- Controlling the depth of a crawl
- Controlling the length of a crawl
- Handling paginated websites
- Handling forms and forms-based authorization
- Handling basic authorization
- Preventing bans by scraping via proxies
- Randomizing user agents
- Caching responses
-
Text Wrangling and Analysis
- Introduction
- Installing NLTK
- Performing sentence splitting
- Performing tokenization
- Performing stemming
- Performing lemmatization
- Determining and removing stop words
- Calculating the frequency distributions of words
- Identifying and removing rare words
- Identifying and removing rare words
- Removing punctuation marks
- Piecing together n-grams
- Scraping a job listing from StackOverflow 
- Reading and cleaning the description in the job listing
-
Searching, Mining and Visualizing Data
- Introduction
- Geocoding an IP address
- How to collect IP addresses of Wikipedia edits
- Visualizing contributor location frequency on Wikipedia
- Creating a word cloud from a StackOverflow job listing
- Crawling links on Wikipedia
- Visualizing page relationships on Wikipedia
- Calculating degrees of separation
- Creating a Simple Data API
-
Creating Scraper Microservices with Docker
- Introduction
- Installing Docker
- Installing a RabbitMQ container from Docker Hub
- Running a Docker container (RabbitMQ)
- Creating and running an Elasticsearch container
- Stopping/restarting a container and removing the image
- Creating a generic microservice with Nameko
- Creating a scraping microservice
- Creating a scraper container
- Creating an API container
- Composing and running the scraper locally with docker-compose
-
Making the Scraper as a Service Real
- Introduction
- Creating and configuring an Elastic Cloud trial account
- Accessing the Elastic Cloud cluster with curl
- Connecting to the Elastic Cloud cluster with Python
- Performing an Elasticsearch query with the Python API 
- Using Elasticsearch to query for jobs with specific skills
- Modifying the API to search for jobs by skill
- Storing configuration in the environment 
- Creating an AWS IAM user and a key pair for ECS
- Configuring Docker to authenticate with ECR
- Pushing containers into ECR
- Creating an ECS cluster
- Creating a task to run our containers
- Starting and accessing the containers in AWS
- Other Books You May Enjoy
Product information
- Title: Python Web Scraping Cookbook
- Author(s):
- Release date: February 2018
- Publisher(s): Packt Publishing
- ISBN: 9781787285217
You might also like
book
Python Web Scraping - Second Edition
Successfully scrape data from any website with the power of Python 3.x About This Book A …
book
Web Scraping with Python
Learn web scraping and crawling techniques to access unlimited data from any web source in any …
book
Web Scraping with Python
Successfully scrape data from any website with the power of Python About This Book A hands-on …
book
Hands-On Web Scraping with Python
Collect and scrape different complexities of data from the modern Web using the latest tools, best …