为什么这个YouTube抓取工具在python中没有显示输出?

时间:2017-09-03 09:35:14

标签: python beautifulsoup web-crawler

import requests 
from bs4 import BeautifulSoup 

youtube = "https://www.youtube.com/results?search_query=" 

def get_address(keyword): 
    query = youtube + keyword 
    source_code = requests.get(query) 
    plain_text = source_code.text 
    soup = BeautifulSoup(plain_text, "html.parser") 

    for link in soup.findAll('a', {'id': 'video-title'}): 
        href = link.get('href') 
        print(href)
        break

get_address("scishow")

程序成功运行,但不显示视频地址,而是在输出中不显示任何内容。

1 个答案:

答案 0 :(得分:0)

Youtube在javascript上运行很大。我建议你用硒。这是您更新的代码:

{{1}}