0% found this document useful (0 votes)
16 views

SMA exp 2

The document outlines an experiment for data collection from social media platforms, focusing on scraping, crawling, and parsing data for business insights. It details the use of various APIs from platforms like Twitter, Facebook, LinkedIn, and YouTube to access structured data, along with a code example for fetching YouTube comments. The conclusion confirms the successful scraping of comments from a YouTube video using an API key.

Uploaded by

mgade3012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

SMA exp 2

The document outlines an experiment for data collection from social media platforms, focusing on scraping, crawling, and parsing data for business insights. It details the use of various APIs from platforms like Twitter, Facebook, LinkedIn, and YouTube to access structured data, along with a code example for fetching YouTube comments. The conclusion confirms the successful scraping of comments from a YouTube video using an API key.

Uploaded by

mgade3012
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Artificial Intelligence

&
Data Science

Subject: Big Data Analysis Course Code: CSDOL8023


Semester: 8 Course: AI&DS
Laboratory no.: 407 Name of subject teacher: Prof. Gitanjali Korgaonkar
Name of student: Meghana Gade Roll no: VU2S2223002

Experiment No. 2

Aim: Data Collection-Select the social media platforms of your choice (Twitter, Facebook, LinkedIn,
YouTube, Web blogs etc.) connect and capture social media data for business (scraping, crawling, parsing).

Theory:
Collecting data from social media platforms is a crucial process for businesses seeking to understand customer
behaviour, market trends, and brand sentiment. By scraping, crawling, and parsing data from platforms like
Twitter, Facebook, LinkedIn, YouTube, and web blogs, companies can access valuable insights to inform their
strategies for business purposes.

1. Social Media Platforms


Social media platforms like Twitter, Facebook, LinkedIn, YouTube, and blogs serve as rich data sources for
understanding user interactions, sentiment, and preferences. Each platform provides unique data types, such as
tweets, posts, comments, reactions, and shares.

2. APIs for Data Access


Most platforms offer APIs (Application Programming Interfaces) that allow developers to access and retrieve
structured data. For example:
 Twitter API: Enables fetching tweets, user profiles, and trending topics.
o Twitter API Documentation
 Facebook Graph API: Allows access to posts, comments, and page insights.
o Facebook Graph API Documentation
 LinkedIn API: Provides company posts and user engagement data.
o LinkedIn API Documentation
 YouTube Data API: Facilitates retrieval of video metadata, comments, and analytics.
o YouTube Data API Documentation
 Web Scraping for Blogs: Used to extract content and metadata from blogs and news articles.
o For web scraping, tools like BeautifulSoup, Scrapy, or Selenium are commonly used.
Code:
import requests

def get_youtube_comments(video_id, api_key):


# Base URL for the YouTube Data API
base_url = "https://www.googleapis.com/youtube/v3/commentThreads"

# Parameters for the API request


params = {
"part": "snippet",
"videoId": video_id,
"key": api_key,
"maxResults": 100
}

comments = []

while True:
response = requests.get(base_url, params=params)

if response.status_code != 200:
print("Error fetching data:", response.json())
break

data = response.json()

# Extract comments from the response


for item in data.get("items", []):
comment = item["snippet"]["topLevelComment"]["snippet"]["textDisplay"]
comments.append(comment)

# Check if there is a nextPageToken for pagination


next_page_token = data.get("nextPageToken")
if not next_page_token:
break

# Update params with the nextPageToken


params["pageToken"] = next_page_token

return comments

if __name__ == "__main__":
API_KEY = "AIzaSyBLOxB1E2lUfTKgQaO44XYNBfFhKBTVYqg"
VIDEO_ID = "3i1OB6wKYms"
comments = get_youtube_comments(VIDEO_ID, API_KEY)
print(f"Fetched {len(comments)} comments:")
for i, comment in enumerate(comments[:10], start=1):
print(f"{i}. {comment}")
Output:

Conclusion: Comments of You Tube video were successfully scrapped using API Key.

R1 R2 R3
DOP DOS Conduction File Record Viva -Voice Total Signature
5 Marks 5 Marks 5 Marks 15 Marks

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy