Code Monkey home page Code Monkey logo

trending-youtube-scraper's Introduction

Trending YouTube Video Scraper

Originally used to build this dataset on Kaggle, which has about 6 months worth of trending YouTube videos on it. This script will scrape the most relevant information from videos that are currently trending on YouTube in a specified set of countries. You can find example output files in the output directory.

Trending YouTube videos for whatever country you are in currently can be found here.

Prerequisites

API Key

In order to use this script, you will need a valid API key for the YouTube Data API. It is free and the instructions for doing so are here. It is slightly awkward to get a key, but if you follow the instructions you should be ok.

Once you have the key, put it inside a text file named api_key.txt in the same directory as the script, or if it's not in the same directory you can target it with the --key_path parameter.

Modules

The only module needed that is not in the standard library is the requests module.

Country Codes

In order to run, the script needs country codes for the countries to collect trending videos from. These are 2 letter country abbreviations according to ISO 3166-1. A list of all existing ones can be found here, however not all of these are assured to work with the YouTube API. This project comes with a list of 10 inside the country_codes.txt file.

Running the Script

The script is fairly simple to run, it takes the following optional parameters:

  • --key_path which takes a path argument that targets the text file containing your API key. By default this is api_key.txt in the current directory.
  • --country_code_path which takes a path argument that targets the text file containing the list of country codes to target. By default this is country_codes.txt in the current directory.
  • --output_dir which takes a path argument that specifies the folder to create the output CSV files for each country. By default this is output/ in the current directory.

License

This project is licensed under the BSD 2-Clause License - see the LICENSE.md file for details

trending-youtube-scraper's People

Contributors

mitchelljy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trending-youtube-scraper's Issues

Data for CategoryId by Country

What script, if any, did you use to compile VideoCategories, based on Youtube's CategoryId, which are said to be Region or Country Specific?

Would appreciate if that could also be included on future release, or commits.
Thank you.

CSV Output Files are Empty

I tried running the script today and while it did complete successfully, all the CSVs that it created were empty except for the headers.. I put my API key in the provided text file. The country codes are the same with the addition of PH for the Philippines.

image
image

Blank Output Files

Hi,

I came across this repo from my colleague. After I obtained a YouTube API Key and placed it in api_key.txt and ran the script, I got blank output files. However, I am not sure which part I did wrong because it did not return any error message.

thanks.

Dataset from Italy

I tried to get a dataset from Italy, but it seems not working. Can you help me please? It's for a project in my university

How to get deal with new "like" and "dislike" from youtube?

Now the scraper can't find the likeCount nor the dislikeCount in any video from YouTube...
I guess this is happening due to the new version of YouTube in 2023, as the scraper can't find the likeCount and dislikeCount in statistics.

There is any fix for this issue?
Thanks in advance!

Can't add content to the file

I've run this script on my Ubuntu but the output file just shows headers.
I have also changed my locale by setting hl=vi&regionCode=VN.
What need i do?

"No filter selected"

Hi,

I get this when using print(request.json()):

{u'error': {u'code': 400, u'message': u'No filter selected. Expected one of: myRated, idParam, id, chart', u'errors': [{u'locationType': u'parameter', u'domain': u'youtube.parameter', u'message': u'No filter selected. Expected one of: myRated, idParam, id, chart', u'reason': u'missingRequiredParameter', u'location': u''}]}}

Any idea what to do?

Scrap trending videos from the past

Hi,

I came across this youtube scraper from kaggle and think it's the perfect script to get relevant information about current trending videos on youtube. However, I was wondering if there's a way to get trending videos from the past? The kaggle dataset is not up to date and I would like to create a new dataset for a project that I'm doing for school. Is there any way to do that with this script?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.