在汤中找到第一个链接

时间:2015-11-03 00:30:16

标签: python beautifulsoup

我有问题! 我试图用美丽的汤找到视频的来源!

link = 'http://oddshot.tv/shot/dreamhackcs-20151101122251803'
r = requests.get(link)
plain_text = r.text
#print(r.text)
soup = BeautifulSoup(plain_text, "html.parser")
link_source = soup.find('source', src=True, href=False)
print(link_source)

然而它会返回:

<source src="https://d301dinc95ec5f.cloudfront.net/capture/dreamhackcs-20151101122251803.shot.mp4" type="video/mp4"><p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that<a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p></source>

现在该视频的来源已经存在,但我不知道如何将其转换为另一个变量以便稍后在我的程序中使用!

1 个答案:

答案 0 :(得分:3)

只需替换

print(link_source)

print(link_source.get('src'))

有关详细信息,请查看the documenttag.get()部分)。