【问题标题】:WebScraping Video on a Youtube Channel Using Beautiful Soup使用 Beautiful Soup 在 Youtube 频道上抓取视频
【发布时间】:2021-10-07 14:26:56
【问题描述】:

如何获取 youtube 频道上视频的视频标题和链接?

我想要的是用 BeautifulSoup 构建一个网络爬虫,它可以提取从 youtube 频道上的视频中发布的所有标题、视图、不喜欢和喜欢、cmets 和日期。

我使用的方法是首先提取视频广告 URL 的标题,然后使用该 URL 获取有关视频的详细信息。

到目前为止,我还没有运气。下面是一个测试网址

url = 'https://www.youtube.com/c/AlexTheAnalyst/videos'

【问题讨论】:

    标签: python web-scraping beautifulsoup data-analysis


    【解决方案1】:

    试试这个,我已经提取了 youtube 视频,这些代码可以帮助你:

    from selenium import webdriver
        PATH="C:\Program Files (x86)\chromedriver.exe"
        url='https://www.youtube.com/channel/UC8tgRQ7DOzAbn9L7zDL8mLg'
        driver =webdriver.Chrome(PATH)
        driver.get(url)
        videos = driver.find_elements_by_class_name("style-scope ytd-grid-video-renderer")
        
        for video in videos:
            title=video.find_element_by_xpath('.//*[@id="video-title"]').text
            days= video.find_element_by_xpath('.//*[@id="metadata-line"]/span[2]').text
            views= video.find_element_by_xpath('.//*[@id="metadata-line"]/span[1]').text
        
            print(title,days,views)
    

    【讨论】:

    • 但你必须安装selenium driverchrome driver
    • 请问如何在我的 Mac 上创建 chrome 驱动程序路径
    • 首先你已经在 C 驱动器中下载了 chrome 驱动程序,然后你将驱动程序粘贴到 C 中,你已经将驱动程序的位置提供给了 selenium
    • 只是我在给path的代码中给出了我在计算机中粘贴的驱动程序的位置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-30
    • 2014-01-28
    • 2016-08-05
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    相关资源
    最近更新 更多