x4nth055/pythoncode-tutorials

web scraping youtube data i used this but its showing error could anyone correct me

kavitanegi369 opened this issue · 3 comments

if name == "main":
import argparse
parser = argparse.ArgumentParser(description="YouTube Video Data Extractor")
parser.add_argument("url", help="URL of the YouTube video")

args = parser.parse_args()
# parse the video URL from command line
url = args.url

data = get_video_info(url)

# print in nice format
print(f"Title: {data['title']}")
print(f"Views: {data['views']}")
print(f"Published at: {data['date_published']}")
print(f"Video Duration: {data['duration']}")
print(f"Video tags: {data['tags']}")
print(f"Likes: {data['likes']}")
print(f"Dislikes: {data['dislikes']}")
print(f"\nDescription: {data['description']}\n")
print(f"\nChannel Name: {data['channel']['name']}")
print(f"Channel URL: {data['channel']['url']}")
print(f"Channel Subscribers: {data['channel']['subscribers'

usage: ipykernel_launcher.py [-h] url
ipykernel_launcher.py: error: unrecognized arguments: -f

Hey there,

This script requires you enter the YouTube video URL in the command line, like so:

python youtube_data_extractor.py https://www.youtube.com/watch?v=jNQXAC9IVRw

Please confirm if this fixes your issue.
Thanks.

i'm using jupyter notebook

Then you shouldn't use argparse, specify your target video URL into url variable in the code, and comment out all argparse code.