{"id":65030,"date":"2025-01-31T14:16:56","date_gmt":"2025-01-31T14:16:56","guid":{"rendered":"https:\/\/proxidize.com\/?post_type=blog&#038;p=65030"},"modified":"2025-11-27T13:54:04","modified_gmt":"2025-11-27T13:54:04","slug":"scrape-youtube-videos","status":"publish","type":"blog","link":"https:\/\/proxidize.com\/blog\/scrape-youtube-videos\/","title":{"rendered":"How to Scrape YouTube Videos: A Step-by-Step Guide"},"content":{"rendered":"\n<p>There are many reasons why someone would want to scrape YouTube videos. YouTube is an excellent data source for video performance, content trends, and audience engagement. Combing through the hundreds of hours a minute of content will be daunting and time consuming. With millions of hours of video content being uploaded monthly, manually analyzing trends is impractical, making automation a necessary solution. When you scrape YouTube videos, you can extract important details such as the title, duration, resolution, and upload date for deeper analysis.<\/p>\n\n\n\n<p>With a script that can scrape YouTube videos, you will save countless hours and gather all the information you need to understand your target demographic and have an outlook of what is trending and why. While you can use the official YouTube API to scrape YouTube videos, the API is limited in its potential. This article will detail how you can use <a href=\"https:\/\/proxidize.com\/blog\/what-is-python\/\" target=\"_blank\" data-type=\"blog\" data-id=\"84057\" rel=\"noreferrer noopener\">Python<\/a> to extract videos and their metadata.&nbsp;<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized centered\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1010\" height=\"569\" src=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/youtube-api-vs-youtube-scraping.png\" alt=\"Image of a computer with gears and a lightbulb and a screwdriver surrounding it. Text above the image reads &quot;YouTube API vs YouTube Scraping&quot;\" class=\"wp-image-65034\" style=\"object-fit:cover\" srcset=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/youtube-api-vs-youtube-scraping.png 1010w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/youtube-api-vs-youtube-scraping-300x169.png 300w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/youtube-api-vs-youtube-scraping-768x433.png 768w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/youtube-api-vs-youtube-scraping-600x338.png 600w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">YouTube API vs YouTube Scraping<\/h2>\n\n\n\n<p>YouTube does have an official way to get data from its platform called the <a href=\"https:\/\/developers.google.com\/youtube\/v3\" target=\"_blank\" rel=\"noreferrer noopener\">YouTube Data API<\/a>. It scrapes information about videos, playlists, and content creators. There are many reasons why someone would choose to scrape YouTube videos themself rather than relying on this API. For starters, you can control what data you need to collect, if you decide to just scrape the titles and views, you can do that with your own scraper as the API has predefined data sets.<\/p>\n\n\n\n<p>When you scrape YouTube videos, you gain access to additional metadata and insights that may not be available through the API. Finally, YouTube APIs are subject to rate limiting as it determines the frequency and volume of requests you can make. By writing your own scraper, you can set your own limits and scrape YouTube videos freely without feeling limited by time or resources. While scraping YouTube offers more flexibility than the YouTube API, it\u2019s important to review the platform\u2019s terms of service to understand any restrictions.<\/p>\n\n\n\n<p>The data that you can scrape from YouTube includes the video title, video description, views, likes, duration, publication date, name of the channel, user description, number of videos, and even the comments and related videos. If you want to scrape video thumbnails, you can extract the URL from the metadata and download the image.<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized centered\"><img decoding=\"async\" width=\"1010\" height=\"569\" src=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/why-scrape-youtube-videos_.png\" alt=\"Image of a phone with four YouTube taps open by its side. Text above image reads &quot;Why Scrape YouTube Videos?&quot;\" class=\"wp-image-65032\" style=\"object-fit:cover\" srcset=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/why-scrape-youtube-videos_.png 1010w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/why-scrape-youtube-videos_-300x169.png 300w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/why-scrape-youtube-videos_-768x433.png 768w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/why-scrape-youtube-videos_-600x338.png 600w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Why Scrape YouTube Videos?<\/h2>\n\n\n\n<p>There are many reasons as to why you should scrape YouTube videos. You could use <a href=\"https:\/\/proxidize.com\/blog\/impact-of-automation-on-data-collection\/\" target=\"_blank\" rel=\"noreferrer noopener\">automate data collection<\/a> from YouTube for sentiment analysis, to learn what people are saying about your business. You could gather valuable insights from text data. Many people use social media to express their thoughts on a brand\u2019s products and services and would be transparent about their opinions, giving you the chance to get a full honest thought of your business practices. Details such as likes and comments are a great way to get insights about your customers. Understanding their preferences can help you improve and customize your products and services based on their insights. When you scrape YouTube videos, brands can analyze target audience behaviors, track trending topics, and determine which content generates the highest engagement. Companies track popular product review videos to gauge consumer sentiment and understand which products are gaining the most traction.<\/p>\n\n\n\n<p>Additionally, you can expand your customer base by using YouTube data. One of the most effective forms of lead generation is through referral marketing also known as word of mouth. People tend to be more trustworthy of a recommendation by a friend or coworker than trusting advertisements. Engagement with customers on social media channels and resolving any complaints they might have is critical to strengthening the customer relationship. When you scrape YouTube videos, you can be informed of any negative comments stated about your business or product and do some damage control before it gets out of hand. <a href=\"https:\/\/proxidize.com\/blog\/market-research\/\">Analyzing metrics<\/a> including likes on video content and comments provides insight into audience approval of a particular video or brand.<\/p>\n\n\n\n<p><\/p>\n\n\n\t\t<div data-elementor-type=\"container\" data-elementor-id=\"85693\" class=\"elementor elementor-85693\" data-elementor-post-type=\"elementor_library\">\n\t\t\t\t<div class=\"elementor-element elementor-element-53838f9 e-con-full no-scale elementor-hidden-mobile_extra elementor-hidden-mobile e-flex e-con e-child\" data-id=\"53838f9\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;gradient&quot;}\">\n\t\t<div class=\"elementor-element elementor-element-264a6ec e-grid e-con-full e-con e-child\" data-id=\"264a6ec\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t<div class=\"elementor-element elementor-element-4986847 e-con-full e-flex e-con e-child\" data-id=\"4986847\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-f8b9092 elementor-widget elementor-widget-heading\" data-id=\"f8b9092\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">High-quality scraping and automation  \nstarts with high-quality mobile proxies<\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-fd5a829 e-con-full e-flex e-con e-child\" data-id=\"fd5a829\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t<div class=\"elementor-element elementor-element-0087840 e-con-full e-flex e-con e-child\" data-id=\"0087840\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1e530dc elementor-widget__width-initial elementor-widget elementor-widget-image\" data-id=\"1e530dc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"125\" height=\"80\" src=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/10\/20-2.svg\" class=\"attachment-full size-full wp-image-86191\" alt=\"\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f634f7d inline-CTA elementor-widget elementor-widget-button\" data-id=\"f634f7d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/proxidize.com\/mobile-proxy-pricing\/?coupon_code=20OFFMPB\" target=\"_blank\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Buy Proxies Now<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\n\n\n\n<p><\/p>\n\n\n\n<p>YouTube\u2019s algorithm ranks videos based on views. Understanding what works best for your specific audience is necessary for increasing your online presence on YouTube. Your company channel will most likely have a variety of video ideas. The YouTube Studio will help you monitor and analyze their performance which, while great, does not help you rank high on YouTube\u2019s search results. Understanding what your competitors are doing can give you an understanding of what their strategy is. Certain factors such as trending topics and keywords can be the difference between ranking high or not ranking at all.<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized centered\"><img loading=\"lazy\" decoding=\"async\" width=\"1010\" height=\"569\" src=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/writing-the-youtube-scraping-script.png\" alt=\"Image of a person sitting on their computer while surrounded by coding scripts. Text above reads &quot;Writing the YouTube Scraping Script&quot;\" class=\"wp-image-65033\" style=\"object-fit:cover\" srcset=\"https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/writing-the-youtube-scraping-script.png 1010w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/writing-the-youtube-scraping-script-300x169.png 300w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/writing-the-youtube-scraping-script-768x433.png 768w, https:\/\/proxidize.com\/wp-content\/uploads\/2025\/01\/writing-the-youtube-scraping-script-600x338.png 600w\" sizes=\"(max-width: 1010px) 100vw, 1010px\" \/><\/figure>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Writing the YouTube Scraping Script<\/h2>\n\n\n\n<p>With all that in mind, it is time to understand how to write the script. If you have used <a href=\"https:\/\/proxidize.com\/blog\/python-libraries-for-web-scraping\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python libraries for web scraping<\/a> before, then this process should be simple and straightforward. If this is your first attempt at writing a scraping script, do not worry. Each step will be explained in detail and each action will be justified.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Up the Environment&nbsp;<\/h3>\n\n\n\n<p>We will present a complete code script in Python so the first step is to ensure that you have the latest version of Python installed. As of the writing of this article, the latest version of <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Python is 3.13.1<\/a>. Once you have confirmed that you have the latest version of Python, open up your IDE and install the necessary libraries.&nbsp;<\/p>\n\n\n\n<p>For this script, you will need the following essential libraries:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/yt-dlp\/yt-dlp\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Yt-dlp<\/a> which will be necessary to scrape YouTube videos<\/li>\n\n\n\n<li>Requests, the simple HTTP library for Python<\/li>\n\n\n\n<li><a href=\"https:\/\/proxidize.com\/blog\/what-is-beautifulsoup\/\" target=\"_blank\" data-type=\"blog\" data-id=\"84203\" rel=\"noreferrer noopener\">BeautifulSoup<\/a> for parsing HTML and extracting the needed data<\/li>\n<\/ul>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The first thing you need to do is to create a new directory which will keep everything organized and easier to navigate through. This can be done by entering the following command in your terminal:<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(1 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>mkdir youtube-scraper\ncd youtube-scraper<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #EA9A97\">mkdir<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">youtube-scraper<\/span><\/span>\n<span class=\"line\"><span style=\"color: #EB6F92; font-style: italic\">cd<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">youtube-scraper<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Next, you will need to install the necessary libraries. As we mentioned previously, these libraries are Requests, BeautifulSoup, and yt-dlp. Enter the following command in your terminal:<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(1 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>pip install yt-dlp requests beautifulsoup4<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #EA9A97\">pip<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">install<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">yt-dlp<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">requests<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">beautifulsoup4<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>With these libraries installed, your environment should be ready to go. Now, we can start writing the script to scrape YouTube videos. We will cover how to scrape YouTube videos and then tackle how to scrape the information such as the titles, views, and comments.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code to Scrape YouTube Videos<\/h3>\n\n\n\n<p><em>Before we move any further, it is important to note that most YouTube videos and the information included in them might be protected by copyright law, intellectual property law, or other similar rights. Before you start to scrape YouTube videos, it is strongly advised that you check if the video you intend to scrape falls under any such protected right.<\/em><\/p>\n\n\n\n<p>To scrape YouTube videos, you will be using the yt-dlp library which is a popular library for downloading videos. For this example, we will be using <a href=\"https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&amp;pp=ygUJcHJveGlkaXpl\" target=\"_blank\" rel=\"noreferrer noopener\">this video from Proxidize\u2019s own YouTube channel<\/a>. To scrape the video, you will need to import the library and then use the <code>download()<\/code> method. Here is a sample script:<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(1 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>from yt_dlp import YoutubeDL\nvideo_url = &#8220;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&amp;pp=ygUJcHJveGlkaXpl&#8221;\nopts = dict()\nwith YoutubeDL(opts) as yt:\n    yt.download([video_url])<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> yt_dlp <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">video_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&amp;pp=ygUJcHJveGlkaXpl&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">opts <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">dict<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">with<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">opts<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> yt<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    yt<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">download<\/span><span style=\"color: #908CAA\">([<\/span><span style=\"color: #E0DEF4\">video_url<\/span><span style=\"color: #908CAA\">])<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>After running the script, you may have found this error message:<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(1 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>WARNING: ffmpeg not found. The downloaded format may not be the best available. Installing ffmpeg is strongly recommended.<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #EA9A97\">WARNING:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">ffmpeg<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">not<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">found.<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">The<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">downloaded<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">format<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">may<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">not<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">be<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">the<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">best<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">available.<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">Installing<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">ffmpeg<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">is<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">strongly<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">recommended.<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The reason this message pops up relates to how YouTube videos tend to have separate audio and video files to them. ffmpeg works with yt-dlp to merge the files together. Without it, there is a chance you will either get a video with no audio or a very low-quality video. This is an easy fix. All you need to do is <a href=\"https:\/\/www.ffmpeg.org\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">download ffmpeg<\/a> through their website.&nbsp;<\/p>\n\n\n\n<p>If you wish to use this script to scrape YouTube videos, all you would need to do is replace the <code>video_url<\/code> with the URL of the video of your choice. Remember to keep the video link within the semicolons. Once you run the script, the scraped YouTube video will be in the same folder as your <code>.py<\/code> file.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Scraping YouTube Video Data<\/h3>\n\n\n\n<p>Now that you have the video, you have an easier way to watch the specific content you want to analyze. What if you wanted the video\u2019s metadata? Well, that requires a whole different script but will still use the same prerequisites. You can use the <code>extract_info<\/code> method with the <code>download=False<\/code> parameter so you will not get the video download file again and will just get the needed information.<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(2 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>from yt_dlp import YoutubeDL\n  \nvideo_url = &#8220;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&#8221;\nopts = dict()\n  \nwith YoutubeDL(opts) as yt:\n    info = yt.extract_info(video_url, download=False)\n    video_title = info.get(&#8220;title&#8221;)\n    width = info.get(&#8220;width&#8221;)\n    height = info.get(&#8220;height&#8221;)\n    language = info.get(&#8220;language&#8221;)\n    channel = info.get(&#8220;channel&#8221;)\n    likes = info.get(&#8220;like_count&#8221;)\n      \n    data = {\n        &#8220;URL&#8221;: video_url,\n        &#8220;Title&#8221;: video_title,\n        &#8220;Width&#8221;: width,\n        &#8220;Height&#8221;: height,\n        &#8220;Language&#8221;: language,\n        &#8220;Channel&#8221;: channel,\n        &#8220;Likes&#8221;: likes\n    }\n    print(data)<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> yt_dlp <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">video_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">opts <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">dict<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">with<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">opts<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> yt<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    info <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> yt<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">extract_info<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">video_url<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">download<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #EA9A97\">False<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    video_title <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;title&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    width <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;width&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    height <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;height&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    language <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;language&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    channel <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;channel&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    likes <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;like_count&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">      <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    data <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;URL&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> video_url<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Title&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> video_title<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Width&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> width<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Height&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> height<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Language&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> language<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Channel&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> channel<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #F6C177\">&quot;Likes&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> likes<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">data<\/span><span style=\"color: #908CAA\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This script will print out the video&#8217;s URL, its title, its resolution, and its language. If you plan to scrape YouTube videos with this script, remember to change the URL to the video you wish to gather the information from.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Scrape YouTube Comments<\/h3>\n\n\n\n<p>If you also want to scrape YouTube video comments, you will need to add the additional option <code>getcomments<\/code> when using yt-dlp. Once you set <code>getcomments<\/code> to True, the <code>extract_info()<\/code> method will then gather all the comment threads with all the information attached to them. Your script will look like this:<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(2 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>from yt_dlp import YoutubeDL\nfrom pprint import pprint\nvideo_url = &#8220;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&#8221;\nopts = {\n    &#8220;getcomments&#8221;: True\n}\nwith YoutubeDL(opts) as yt:\n    info = yt.extract_info(video_url, download=False)\n    comments = info[&#8220;comments&#8221;]\n    thread_count = info[&#8220;comment_count&#8221;]\n    print(&#8220;Number of threads: {}&#8221;.format(thread_count))\n    pprint(comments)<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> yt_dlp <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> pprint <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> pprint<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">video_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/watch?v=M-hAQ5nkSMs&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">opts <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #F6C177\">&quot;getcomments&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">with<\/span><span style=\"color: #E0DEF4\"> YoutubeDL<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">opts<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> yt<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    info <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> yt<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">extract_info<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">video_url<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">download<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #EA9A97\">False<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    comments <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&quot;comments&quot;<\/span><span style=\"color: #908CAA\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    thread_count <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&quot;comment_count&quot;<\/span><span style=\"color: #908CAA\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;Number of threads: <\/span><span style=\"color: #3E8FB0\">{}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">format<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">thread_count<\/span><span style=\"color: #908CAA\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    pprint<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">comments<\/span><span style=\"color: #908CAA\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">How to Scrape YouTube Channel Information&nbsp;<\/h3>\n\n\n\n<p>To scrape the YouTube channel information, things start to get a bit trickier. Scraping this information requires you to utilize a <a href=\"https:\/\/proxidize.com\/proxy-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">proxy server<\/a> as without one, your script will either come up empty or you will get an error message stating that the attempt was blocked by YouTube\u2019s anti-bot protection measure. Below, we have provided a script that will help you scrape a YouTube channel\u2019s about page by using Proxidize\u2019s rotating <a href=\"https:\/\/proxidize.com\/proxy-server\/mobile-proxy\/\" target=\"_blank\" rel=\"noreferrer noopener\">mobile proxies<\/a>.<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(2 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>import requests\nfrom bs4 import BeautifulSoup\nimport time\nimport random\n# Replace with your Proxidize mobile proxy IP and port\nPROXY_IP = &#8220;YOUR_PROXIDIZE_IP&#8221;\nPROXY_PORT = &#8220;YOUR_PROXIDIZE_PORT&#8221;\nPROXY_USERNAME = &#8220;YOUR_USERNAME&#8221;  # If authentication is required\nPROXY_PASSWORD = &#8220;YOUR_PASSWORD&#8221;  # If authentication is required\n# Proxy configuration\nproxy_url = f&#8221;http:\/\/{PROXY_USERNAME}:{PROXY_PASSWORD}@{PROXY_IP}:{PROXY_PORT}&#8221;\nproxies = {&#8220;http&#8221;: proxy_url, &#8220;https&#8221;: proxy_url}\n# Headers to mimic a real browser\nHEADERS = {\n    &#8220;User-Agent&#8221;: &#8220;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/119.0.0.0 Safari\/537.36&#8221;,\n    &#8220;Accept-Language&#8221;: &#8220;en-US,en;q=0.9&#8221;,\n}\n# YouTube channel &#8220;About&#8221; page URL\nchannel_url = &#8220;https:\/\/www.youtube.com\/@proxidize\/about&#8221;\ndef get_channel_info():\n    try:\n        response = requests.get(channel_url, headers=HEADERS, proxies=proxies, timeout=10)\n        if response.status_code == 200:\n            soup = BeautifulSoup(response.text, &#8220;html.parser&#8221;)\n            \n            # Extract channel name and description\n            channel_name = soup.find(&#8220;yt-formatted-string&#8221;, {&#8220;id&#8221;: &#8220;text&#8221;, &#8220;class&#8221;: &#8220;style-scope ytd-channel-name&#8221;})\n            channel_desc = soup.find(&#8220;div&#8221;, {&#8220;id&#8221;: &#8220;wrapper&#8221;, &#8220;class&#8221;: &#8220;style-scope ytd-channel-tagline-renderer&#8221;})\n            \n            return {\n                &#8220;channel_name&#8221;: channel_name.text.strip() if channel_name else &#8220;Not Found&#8221;,\n                &#8220;channel_desc&#8221;: channel_desc.text.strip() if channel_desc else &#8220;Not Found&#8221;,\n            }\n        else:\n            print(f&#8221;Failed to fetch page. Status Code: {response.status_code}&#8221;)\n            return None\n    except Exception as e:\n        print(f&#8221;Error: {e}&#8221;)\n        return None\n# Rotating Proxies: Change IP after each request\ndef rotate_ip():\n    print(&#8220;Rotating IP&#8230;&#8221;)\n    time.sleep(random.randint(5, 10))  # Simulate human behavior\n    # Proxidize allows manual IP refresh (if needed, trigger it via API)\nif __name__ == &#8220;__main__&#8221;:\n    for _ in range(3):  # Rotate 3 times\n        info = get_channel_info()\n        if info:\n            print(info)\n        rotate_ip()<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> requests<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> bs4 <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> random<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Replace with your Proxidize mobile proxy IP and port<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXY_IP<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_IP&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXY_PORT<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_PORT&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXY_USERNAME<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_USERNAME&quot;<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> If authentication is required<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXY_PASSWORD<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PASSWORD&quot;<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> If authentication is required<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Proxy configuration<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">proxy_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;http:\/\/<\/span><span style=\"color: #3E8FB0\">{PROXY_USERNAME}<\/span><span style=\"color: #F6C177\">:<\/span><span style=\"color: #3E8FB0\">{PROXY_PASSWORD}<\/span><span style=\"color: #F6C177\">@<\/span><span style=\"color: #3E8FB0\">{PROXY_IP}<\/span><span style=\"color: #F6C177\">:<\/span><span style=\"color: #3E8FB0\">{PROXY_PORT}<\/span><span style=\"color: #F6C177\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">proxies <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #F6C177\">&quot;http&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> proxy_url<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> proxy_url<\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Headers to mimic a real browser<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">HEADERS<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #F6C177\">&quot;User-Agent&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/119.0.0.0 Safari\/537.36&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #F6C177\">&quot;Accept-Language&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;en-US,en;q=0.9&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> YouTube channel &quot;About&quot; page URL<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">channel_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/@proxidize\/about&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">get_channel_info<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">try<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        response <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> requests<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">channel_url<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">headers<\/span><span style=\"color: #3E8FB0\">=HEADERS<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">proxies<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\">proxies<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #C4A7E7; font-style: italic\">timeout<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #EA9A97\">10<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> response<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">status_code <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">200<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            soup <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">response<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;html.parser&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Extract channel name and description<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            channel_name <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> soup<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">find<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;yt-formatted-string&quot;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #F6C177\">&quot;id&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;text&quot;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;class&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;style-scope ytd-channel-name&quot;<\/span><span style=\"color: #908CAA\">})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            channel_desc <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> soup<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">find<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;div&quot;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><span style=\"color: #F6C177\">&quot;id&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;wrapper&quot;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;class&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;style-scope ytd-channel-tagline-renderer&quot;<\/span><span style=\"color: #908CAA\">})<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">                <\/span><span style=\"color: #F6C177\">&quot;channel_name&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> channel_name<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> channel_name <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;Not Found&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">                <\/span><span style=\"color: #F6C177\">&quot;channel_desc&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> channel_desc<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> channel_desc <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;Not Found&quot;<\/span><span style=\"color: #908CAA\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #908CAA\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;Failed to fetch page. Status Code: <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">response<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">status_code<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">None<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">except<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">Exception<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> e<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;Error: <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">e<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">None<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Rotating Proxies: Change IP after each request<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">rotate_ip<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;Rotating IP...&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    time<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">sleep<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">random<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">randint<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #EA9A97\">5<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">10<\/span><span style=\"color: #908CAA\">))<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Simulate human behavior<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Proxidize allows manual IP refresh (if needed, trigger it via API)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">__name__<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;__main__&quot;<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">for<\/span><span style=\"color: #E0DEF4\"> _ <\/span><span style=\"color: #3E8FB0\">in<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EB6F92; font-style: italic\">range<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #EA9A97\">3<\/span><span style=\"color: #908CAA\">):<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Rotate 3 times<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        info <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> get_channel_info<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> info<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">info<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        rotate_ip<\/span><span style=\"color: #908CAA\">()<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>This script will use a mobile proxy to access YouTube anonymously and fetch the YouTube channel\u2019s name and description from the about page. It will also rotate the proxy after each request which will prevent any blocks and lessen your chances of getting an IP ban. It will also mimic a real browser by using headings which will allow you to run the script multiple times without getting blocked.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Scrape YouTube Search Results<\/h3>\n\n\n\n<p>Using a mobile proxy you can scrape the YouTube search results page. However, if you wish to do this, you will need to incorporate Selenium to bypass bot detection and render the <a href=\"https:\/\/proxidize.com\/blog\/what-is-javascript\/\" target=\"_blank\" data-type=\"blog\" data-id=\"83360\" rel=\"noreferrer noopener\">JavaScript<\/a> which Request and BS4 cannot do alone. The script below presents how you can scrape the YouTube search keyword \u201cmobile proxies\u201d.<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(2 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>import time\nimport requests\nimport undetected_chromedriver as uc\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.chrome.options import Options\nfrom bs4 import BeautifulSoup\n# Proxidize API credentials\nPROXIDIZE_API_KEY = &#8220;YOUR_PROXIDIZE_API_KEY&#8221;\nPROXIDIZE_PROXY_URL = &#8220;YOUR_PROXIDIZE_PROXY_URL&#8221;  # Format: http:\/\/USER:PASS@IP:PORT\n# YouTube search URL for &#8220;mobile proxies&#8221;\nsearch_query = &#8220;mobile proxies&#8221;\nsearch_url = f&#8221;https:\/\/www.youtube.com\/results?search_query={search_query.replace(&#8216; &#8216;, &#8216;+&#8217;)}&#8221;\n# Function to refresh Proxidize IP\ndef refresh_proxy():\n    response = requests.get(f&#8221;https:\/\/api.proxidize.com\/v1\/proxies\/rotate?api_key={PROXIDIZE_API_KEY}&#8221;)\n    if response.status_code == 200:\n        print(&#8220;IP rotated successfully&#8221;)\n    else:\n        print(&#8220;Failed to rotate IP&#8221;)\n# Set up Selenium with Proxidize mobile proxy\ndef get_search_results():\n    options = uc.ChromeOptions()\n    options.add_argument(f&#8221;&#8211;proxy-server={PROXIDIZE_PROXY_URL}&#8221;)  # Use Proxidize proxy\n    options.add_argument(&#8220;&#8211;headless&#8221;)  # Run in headless mode\n    options.add_argument(&#8220;&#8211;disable-blink-features=AutomationControlled&#8221;)  # Hide Selenium\n    driver = uc.Chrome(options=options)\n    try:\n        driver.get(search_url)\n        time.sleep(5)  # Allow page to load\n        # Get page source and parse it with BeautifulSoup\n        soup = BeautifulSoup(driver.page_source, &#8220;html.parser&#8221;)\n        results = []\n        for video in soup.select(&#8220;ytd-video-renderer&#8221;):\n            title = video.select_one(&#8220;#video-title&#8221;).text.strip()\n            link = &#8220;https:\/\/www.youtube.com&#8221; + video.select_one(&#8220;#video-title&#8221;)[&#8220;href&#8221;]\n            views = video.select_one(&#8220;#metadata-line span&#8221;).text.strip() if video.select_one(&#8220;#metadata-line span&#8221;) else &#8220;N\/A&#8221;\n            \n            results.append({&#8220;title&#8221;: title, &#8220;link&#8221;: link, &#8220;views&#8221;: views})\n        return results\n    finally:\n        driver.quit()\nif __name__ == &#8220;__main__&#8221;:\n    refresh_proxy()  # Rotate IP before scraping\n    search_results = get_search_results()\n    if search_results:\n        for idx, video in enumerate(search_results[:10]):  # Print first 10 results\n            print(f&#8221;{idx+1}. {video[&#8216;title&#8217;]} &#8211; {video[&#8216;views&#8217;]}\\n   {video[&#8216;link&#8217;]}\\n&#8221;)<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> requests<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> undetected_chromedriver <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> uc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> selenium<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">webdriver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">common<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">by <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> By<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> selenium<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">webdriver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">chrome<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">options <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> Options<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> bs4 <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Proxidize API credentials<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXIDIZE_API_KEY<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_API_KEY&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXIDIZE_PROXY_URL<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_PROXY_URL&quot;<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Format: http:\/\/USER:PASS@IP:PORT<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> YouTube search URL for &quot;mobile proxies&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">search_query <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;mobile proxies&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">search_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/results?search_query=<\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">search_query<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">replace<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&#39; &#39;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&#39;+&#39;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Function to refresh Proxidize IP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">refresh_proxy<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    response <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> requests<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;https:\/\/api.proxidize.com\/v1\/proxies\/rotate?api_key=<\/span><span style=\"color: #3E8FB0\">{PROXIDIZE_API_KEY}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> response<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">status_code <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">200<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;IP rotated successfully&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;Failed to rotate IP&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Set up Selenium with Proxidize mobile proxy<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">get_search_results<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> uc<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">ChromeOptions<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;--proxy-server=<\/span><span style=\"color: #3E8FB0\">{PROXIDIZE_PROXY_URL}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Use Proxidize proxy<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;--headless&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Run in headless mode<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;--disable-blink-features=AutomationControlled&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Hide Selenium<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    driver <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> uc<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">Chrome<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #C4A7E7; font-style: italic\">options<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\">options<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">try<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">search_url<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        time<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">sleep<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #EA9A97\">5<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Allow page to load<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Get page source and parse it with BeautifulSoup<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        soup <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">page_source<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;html.parser&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        results <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">[]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">for<\/span><span style=\"color: #E0DEF4\"> video <\/span><span style=\"color: #3E8FB0\">in<\/span><span style=\"color: #E0DEF4\"> soup<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;ytd-video-renderer&quot;<\/span><span style=\"color: #908CAA\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            title <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#video-title&quot;<\/span><span style=\"color: #908CAA\">).<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            link <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">+<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#video-title&quot;<\/span><span style=\"color: #908CAA\">)[<\/span><span style=\"color: #F6C177\">&quot;href&quot;<\/span><span style=\"color: #908CAA\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            views <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#metadata-line span&quot;<\/span><span style=\"color: #908CAA\">).<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#metadata-line span&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;N\/A&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            results<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">append<\/span><span style=\"color: #908CAA\">({<\/span><span style=\"color: #F6C177\">&quot;title&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> title<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;link&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> link<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;views&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> views<\/span><span style=\"color: #908CAA\">})<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> results<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">finally<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">quit<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">__name__<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;__main__&quot;<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    refresh_proxy<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Rotate IP before scraping<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    search_results <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> get_search_results<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> search_results<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">for<\/span><span style=\"color: #E0DEF4\"> idx<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> video <\/span><span style=\"color: #3E8FB0\">in<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EB6F92; font-style: italic\">enumerate<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">search_results<\/span><span style=\"color: #908CAA\">[:<\/span><span style=\"color: #EA9A97\">10<\/span><span style=\"color: #908CAA\">]):<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Print first 10 results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">idx<\/span><span style=\"color: #3E8FB0\">+<\/span><span style=\"color: #EA9A97\">1<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">. <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;title&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\"> - <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;views&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}\\n<\/span><span style=\"color: #F6C177\">   <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;link&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}\\n<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Full Script to Scrape YouTube Videos, Including Metadata<\/h3>\n\n\n\n<p>If you want to scrape everything from the YouTube video to the comments and the channel, its description, and a YouTube search result, we have you covered. This script will take care of it all. All you would need to do is enter your proxy information and change the URLs to whichever page and\/or account you wish to scrape.<\/p>\n\n\n\n<p>As an added bonus, this script will save all the information into a JSON file. When scraping at scale, using automated <a href=\"https:\/\/proxidize.com\/blog\/captcha-solvers\/\" data-type=\"blog\" data-id=\"54145\" target=\"_blank\" rel=\"noreferrer noopener\">captcha solvers<\/a> can help bypass YouTube\u2019s bot detection mechanisms.<\/p>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#e0def4;--cbp-line-number-width:calc(2 * 0.6 * .75rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" style=\"color:#e0def4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><textarea class=\"code-block-pro-copy-button-textarea\" aria-hidden=\"true\" readonly>import time\nimport requests\nimport undetected_chromedriver as uc\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.chrome.options import Options\nfrom bs4 import BeautifulSoup\n# Proxidize API credentials\nPROXIDIZE_API_KEY = &#8220;YOUR_PROXIDIZE_API_KEY&#8221;\nPROXIDIZE_PROXY_URL = &#8220;YOUR_PROXIDIZE_PROXY_URL&#8221;  # Format: http:\/\/USER:PASS@IP:PORT\n# YouTube search URL for &#8220;mobile proxies&#8221;\nsearch_query = &#8220;mobile proxies&#8221;\nsearch_url = f&#8221;https:\/\/www.youtube.com\/results?search_query={search_query.replace(&#8216; &#8216;, &#8216;+&#8217;)}&#8221;\n# Function to refresh Proxidize IP\ndef refresh_proxy():\n    response = requests.get(f&#8221;https:\/\/api.proxidize.com\/v1\/proxies\/rotate?api_key={PROXIDIZE_API_KEY}&#8221;)\n    if response.status_code == 200:\n        print(&#8220;IP rotated successfully&#8221;)\n    else:\n        print(&#8220;Failed to rotate IP&#8221;)\n# Set up Selenium with Proxidize mobile proxy\ndef get_search_results():\n    options = uc.ChromeOptions()\n    options.add_argument(f&#8221;&#8211;proxy-server={PROXIDIZE_PROXY_URL}&#8221;)  # Use Proxidize proxy\n    options.add_argument(&#8220;&#8211;headless&#8221;)  # Run in headless mode\n    options.add_argument(&#8220;&#8211;disable-blink-features=AutomationControlled&#8221;)  # Hide Selenium\n    driver = uc.Chrome(options=options)\n    try:\n        driver.get(search_url)\n        time.sleep(5)  # Allow page to load\n        # Get page source and parse it with BeautifulSoup\n        soup = BeautifulSoup(driver.page_source, &#8220;html.parser&#8221;)\n        results = []\n        for video in soup.select(&#8220;ytd-video-renderer&#8221;):\n            title = video.select_one(&#8220;#video-title&#8221;).text.strip()\n            link = &#8220;https:\/\/www.youtube.com&#8221; + video.select_one(&#8220;#video-title&#8221;)[&#8220;href&#8221;]\n            views = video.select_one(&#8220;#metadata-line span&#8221;).text.strip() if video.select_one(&#8220;#metadata-line span&#8221;) else &#8220;N\/A&#8221;\n            \n            results.append({&#8220;title&#8221;: title, &#8220;link&#8221;: link, &#8220;views&#8221;: views})\n        return results\n    finally:\n        driver.quit()\nif __name__ == &#8220;__main__&#8221;:\n    refresh_proxy()  # Rotate IP before scraping\n    search_results = get_search_results()\n    if search_results:\n        for idx, video in enumerate(search_results[:10]):  # Print first 10 results\n            print(f&#8221;{idx+1}. {video[&#8216;title&#8217;]} &#8211; {video[&#8216;views&#8217;]}\\n   {video[&#8216;link&#8217;]}\\n&#8221;)<\/textarea><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki rose-pine-moon\" style=\"background-color: #232136\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> requests<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> undetected_chromedriver <\/span><span style=\"color: #3E8FB0\">as<\/span><span style=\"color: #E0DEF4\"> uc<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> selenium<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">webdriver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">common<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">by <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> By<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> selenium<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">webdriver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">chrome<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">options <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> Options<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">from<\/span><span style=\"color: #E0DEF4\"> bs4 <\/span><span style=\"color: #3E8FB0\">import<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Proxidize API credentials<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXIDIZE_API_KEY<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_API_KEY&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">PROXIDIZE_PROXY_URL<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;YOUR_PROXIDIZE_PROXY_URL&quot;<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Format: http:\/\/USER:PASS@IP:PORT<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> YouTube search URL for &quot;mobile proxies&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">search_query <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;mobile proxies&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">search_url <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com\/results?search_query=<\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">search_query<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">replace<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&#39; &#39;<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&#39;+&#39;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Function to refresh Proxidize IP<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">refresh_proxy<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    response <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> requests<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;https:\/\/api.proxidize.com\/v1\/proxies\/rotate?api_key=<\/span><span style=\"color: #3E8FB0\">{PROXIDIZE_API_KEY}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> response<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">status_code <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">200<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;IP rotated successfully&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;Failed to rotate IP&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Set up Selenium with Proxidize mobile proxy<\/span><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">def<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EA9A97\">get_search_results<\/span><span style=\"color: #908CAA\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> uc<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">ChromeOptions<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;--proxy-server=<\/span><span style=\"color: #3E8FB0\">{PROXIDIZE_PROXY_URL}<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Use Proxidize proxy<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;--headless&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Run in headless mode<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    options<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">add_argument<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;--disable-blink-features=AutomationControlled&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Hide Selenium<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    driver <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> uc<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">Chrome<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #C4A7E7; font-style: italic\">options<\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\">options<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">try<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">get<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">search_url<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        time<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">sleep<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #EA9A97\">5<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Allow page to load<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Get page source and parse it with BeautifulSoup<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        soup <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> BeautifulSoup<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">page_source<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;html.parser&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        results <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #908CAA\">[]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">for<\/span><span style=\"color: #E0DEF4\"> video <\/span><span style=\"color: #3E8FB0\">in<\/span><span style=\"color: #E0DEF4\"> soup<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;ytd-video-renderer&quot;<\/span><span style=\"color: #908CAA\">):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            title <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#video-title&quot;<\/span><span style=\"color: #908CAA\">).<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            link <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;https:\/\/www.youtube.com&quot;<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">+<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#video-title&quot;<\/span><span style=\"color: #908CAA\">)[<\/span><span style=\"color: #F6C177\">&quot;href&quot;<\/span><span style=\"color: #908CAA\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            views <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#metadata-line span&quot;<\/span><span style=\"color: #908CAA\">).<\/span><span style=\"color: #E0DEF4\">text<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">strip<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> video<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">select_one<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #F6C177\">&quot;#metadata-line span&quot;<\/span><span style=\"color: #908CAA\">)<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">else<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;N\/A&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            results<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">append<\/span><span style=\"color: #908CAA\">({<\/span><span style=\"color: #F6C177\">&quot;title&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> title<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;link&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> link<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;views&quot;<\/span><span style=\"color: #908CAA\">:<\/span><span style=\"color: #E0DEF4\"> views<\/span><span style=\"color: #908CAA\">})<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">return<\/span><span style=\"color: #E0DEF4\"> results<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">finally<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        driver<\/span><span style=\"color: #908CAA\">.<\/span><span style=\"color: #E0DEF4\">quit<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #9CCFD8\">__name__<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #3E8FB0\">==<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #F6C177\">&quot;__main__&quot;<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    refresh_proxy<\/span><span style=\"color: #908CAA\">()<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Rotate IP before scraping<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    search_results <\/span><span style=\"color: #3E8FB0\">=<\/span><span style=\"color: #E0DEF4\"> get_search_results<\/span><span style=\"color: #908CAA\">()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">    <\/span><span style=\"color: #3E8FB0\">if<\/span><span style=\"color: #E0DEF4\"> search_results<\/span><span style=\"color: #908CAA\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">        <\/span><span style=\"color: #3E8FB0\">for<\/span><span style=\"color: #E0DEF4\"> idx<\/span><span style=\"color: #908CAA\">,<\/span><span style=\"color: #E0DEF4\"> video <\/span><span style=\"color: #3E8FB0\">in<\/span><span style=\"color: #E0DEF4\"> <\/span><span style=\"color: #EB6F92; font-style: italic\">enumerate<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #E0DEF4\">search_results<\/span><span style=\"color: #908CAA\">[:<\/span><span style=\"color: #EA9A97\">10<\/span><span style=\"color: #908CAA\">]):<\/span><span style=\"color: #E0DEF4\">  <\/span><span style=\"color: #908CAA; font-style: italic\">#<\/span><span style=\"color: #6E6A86; font-style: italic\"> Print first 10 results<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E0DEF4\">            <\/span><span style=\"color: #EB6F92; font-style: italic\">print<\/span><span style=\"color: #908CAA\">(<\/span><span style=\"color: #3E8FB0\">f<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">idx<\/span><span style=\"color: #3E8FB0\">+<\/span><span style=\"color: #EA9A97\">1<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\">. <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;title&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}<\/span><span style=\"color: #F6C177\"> - <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;views&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}\\n<\/span><span style=\"color: #F6C177\">   <\/span><span style=\"color: #3E8FB0\">{<\/span><span style=\"color: #E0DEF4\">video<\/span><span style=\"color: #908CAA\">[<\/span><span style=\"color: #F6C177\">&#39;link&#39;<\/span><span style=\"color: #908CAA\">]<\/span><span style=\"color: #3E8FB0\">}\\n<\/span><span style=\"color: #F6C177\">&quot;<\/span><span style=\"color: #908CAA\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Error Handling&nbsp;<\/h3>\n\n\n\n<p>Before you scrape YouTube videos and their metadata, there are several challenges to consider, such as request limits, dynamic content loading, and bot detection measures. YouTube actively monitors automated traffic, which can result in an <a href=\"https:\/\/proxidize.com\/blog\/403-error\/\" target=\"_blank\" rel=\"noreferrer noopener\">error 403<\/a> or an <a href=\"https:\/\/proxidize.com\/blog\/error-code-429\/\" data-type=\"link\" data-id=\"https:\/\/proxidize.com\/blog\/error-code-429\/\" target=\"_blank\" rel=\"noreferrer noopener\">error code 429<\/a> Too Many Requests errors if scraping requests are too frequent.<\/p>\n\n\n\n<p>To avoid this, implementing IP rotation, adjusting request intervals, and using proxies can help maintain uninterrupted scraping. Since YouTube dynamically loads elements like views and comments, using tools that can render JavaScript, such as Selenium, may be necessary. By applying these techniques, you can improve the reliability and efficiency of your YouTube scraping process while minimizing disruptions.<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion&nbsp;<\/h2>\n\n\n\n<p>When you scrape YouTube videos and other relevant data, you are introduced to valuable insights into content performance and audience engagement. By using Python and its many libraries as well as adhering to guidelines, you can effectively scrape YouTube videos.&nbsp;<\/p>\n\n\n\n<p>Key takeaways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scrape YouTube videos to extract data beyond the limitations of the YouTube Data API.<\/li>\n\n\n\n<li>Python libraries like yt-dlp, requests, and BeautifulSoup make it easy to scrape YouTube videos for metadata, comments, and search results.<\/li>\n\n\n\n<li>Installing ffmpeg ensures high-quality video downloads when using yt-dlp to scrape YouTube videos, as it merges separate audio and video streams.<\/li>\n\n\n\n<li>Using proxies and rotating IPs while attempting to scrape YouTube videos helps avoid detection and prevents rate limiting.<\/li>\n<\/ul>\n\n\n\n<p>However, it&#8217;s crucial to remain mindful of legal considerations and platform policies when attempting to scrape YouTube videos to ensure responsible and lawful data collection. Through using proxies, request delays, and error handling, you can optimize the process and prevent detection while scraping.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1738330919992\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is the best tool for market researchers analyzing YouTube data?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A powerful tool for market researchers should include features like proxy support, search result extraction, and audience sentiment analysis.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1738330936645\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do I avoid getting blocked while deciding to scrape YouTube videos?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Utilizing <a href=\"https:\/\/proxidize.com\/blog\/what-is-an-ip-address\/\" target=\"_blank\" data-type=\"blog\" data-id=\"83356\" rel=\"noreferrer noopener\">IP address<\/a> rotation, mobile proxies, and adjusting your scraping speed should help avoid detection.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1738330951458\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">Can I store my scraped data in Google Drive or Google Sheets?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, you can export your data to a Google Sheet or save JSON files in Google Drive for easy access.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1738330960964\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What are common issues to keep in mind when choosing to scrape YouTube videos?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Common issues include IP bans, captcha challenges, and dynamic content loading that prevents data extraction. However, they can be bypassed by using a proxy, implementing a captcha solver, and using Selenium to handle dynamic content.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"author":2627,"featured_media":75388,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","categories":[110],"tags":[],"class_list":["post-65030","blog","type-blog","status-publish","format-standard","has-post-thumbnail","hentry","category-web-scraping-and-automation"],"acf":[],"_links":{"self":[{"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/blog\/65030","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/users\/2627"}],"replies":[{"embeddable":true,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/comments?post=65030"}],"version-history":[{"count":7,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/blog\/65030\/revisions"}],"predecessor-version":[{"id":90516,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/blog\/65030\/revisions\/90516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/media\/75388"}],"wp:attachment":[{"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/media?parent=65030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/categories?post=65030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/proxidize.com\/wp-json\/wp\/v2\/tags?post=65030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}