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")
程序成功运行,但不显示视频地址,而是在输出中不显示任何内容。
答案 0 :(得分:0)
Youtube在javascript上运行很大。我建议你用硒。这是您更新的代码:
{{1}}