playlistfromsong.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:playlistfromsong 作者: schollz 项目源码 文件源码
def getYoutubeURLFromSearch(searchString):
    if pyVersion < 3:
        urlParse = urllib.quote_plus(searchString)
    else:
        urlParse = urllib.parse.quote_plus(searchString)
    urlToGet = "https://www.youtube.com/results?search_query=" + urlParse  # NOQA
    r = get(urlToGet)
    soup = BeautifulSoup(r.content, 'html.parser')
    videos = soup.find_all('h3', class_='yt-lockup-title')
    for video in videos:
        link = video.find_all('a')[0]
        url = "https://www.youtube.com" + link.get('href')
        if 'googleads' in url:
            continue
        title = link.text
        if 'doubleclick' in title:
            continue
        if 'list=' in url:
            continue
        if 'album review' in title.lower():
            continue
        return url
    return ""
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号