Created
June 20, 2021 05:05
-
-
Save dimitryzub/0e11fc832f679acec6e23dab8e48431b to your computer and use it in GitHub Desktop.
youtube_serpapi_get_search_results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from serpapi import GoogleSearch | |
def get_video_results(): | |
params = { | |
"api_key": "YOUR_API_KEY", | |
"engine": "youtube", | |
"search_query": "minecraft" | |
} | |
search = GoogleSearch(params) | |
results = search.get_dict() | |
for results in results['video_results']: | |
title = results['title'] | |
link = results['link'] | |
channel = results['channel'] | |
try: | |
published_date = results['published_date'] | |
except: | |
published_date = None | |
try: | |
views = results['views'] | |
except: | |
views = None | |
try: | |
video_length = results['length'] | |
except: | |
video_length = None | |
try: | |
extensions = results['extensions'] | |
except: | |
extensions = None | |
print(f'{title}\n{link}\n{channel}\n{published_date}\n{views}\n{video_length}\n{extensions}\n') | |
get_video_results() | |
# part of the output: | |
''' | |
I Spent 100 Days in Medieval Times in Minecraft... Here's What Happened | |
https://www.youtube.com/watch?v=hjV30hf6yEM | |
{'name': 'Forge Labs', 'link': 'https://www.youtube.com/user/AirsoftXX', 'verified': True, 'thumbnail': 'https://yt3.ggpht.com/ytc/AAUvwnjgpo-Pvk7jrXkd4HFErsnrLr2Nwru5f8TgtWGJ7w=s68-c-k-c0x00ffffff-no-rj'} | |
6 days ago | |
10136089 | |
1:49:28 | |
['New'] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment