Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Social Media Analytics

You're reading from   Python Social Media Analytics Analyze and visualize data from Twitter, YouTube, GitHub, and more

Arrow left icon
Product type Paperback
Published in Jul 2017
Publisher Packt
ISBN-13 9781787121485
Length 312 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (3):
Arrow left icon
Baihaqi Siregar Baihaqi Siregar
Author Profile Icon Baihaqi Siregar
Baihaqi Siregar
Siddhartha Chatterjee Siddhartha Chatterjee
Author Profile Icon Siddhartha Chatterjee
Siddhartha Chatterjee
Michal Krystyanczuk Michal Krystyanczuk
Author Profile Icon Michal Krystyanczuk
Michal Krystyanczuk
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Introduction to the Latest Social Media Landscape and Importance FREE CHAPTER 2. Harnessing Social Data - Connecting, Capturing, and Cleaning 3. Uncovering Brand Activity, Popularity, and Emotions on Facebook 4. Analyzing Twitter Using Sentiment Analysis and Entity Recognition 5. Campaigns and Consumer Reaction Analytics on YouTube – Structured and Unstructured 6. The Next Great Technology – Trends Mining on GitHub 7. Scraping and Extracting Conversational Topics on Internet Forums 8. Demystifying Pinterest through Network Analysis of Users Interests 9. Social Data Analytics at Scale – Spark and Amazon Web Services

Getting the data

Data harvesting is the entry point for any social media analysis project. There are two main ways to collect data for an analysis: by connecting to APIs or by crawling and scraping the social networks. It is crucial to understand how the data was collected in order to be aware of the bias that might introduced. Different harvesting techniques will require customized approaches to data preprocessing and analysis workflow, which we will explain in further chapters.

Defining API

A widely used term, API (Application Programming Interface) is defined as a set of instructions and standards to access a web based software application. But what does it mean in real life? Firstly, APIs allow users to send a request for a particular resource, such as Facebook or Twitter , and receive some data in response. It is worth noting that all API providers fix some limitations on the quantity or type of data which users can obtain. APIs give access data processing resources, such as AlchemyAPI that receives in a request verbatim (textual data) and sends in response all results of the analysis, such as nouns, verbs, entities, and so on. In our case, the APIs are used either to get data from social networks or to execute some complex processing on them.

In order to access and manipulate APIs, we have to install the urllib2 library:

pip3 install urllib2

In some cases, if you fail to perform the installation. You can also try using the request library, which is compatible with Python 2.x and 3.x.

pip3 install request

Scraping and crawling

Scraping (or web scraping) is a technique to extract information from websites. When we do not have access to APIs, we can only retrieve visible information from HTML generated on a web page. In order to perform the task, we need a scraper that is able to extract information that we need and structure it in a predefined format. The next step is to build a crawler—a tool to follow links on a website and extract the information from all sub pages. When we decide to build a scraping strategy, we have to take into consideration the terms and conditions, as some websites do not allow scraping.

Python offers very useful tools to create scrapers and crawlers, such as beautifulsoup and scrapy.

pip3 install bs4, scrapy 
You have been reading a chapter from
Python Social Media Analytics
Published in: Jul 2017
Publisher: Packt
ISBN-13: 9781787121485
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image