Reputation: 137
I'm trying to get a youtube video link connected to a certain webpage. I've written a script to fetch that link but I've ended up getting an image link instead.
I've tried:
import requests
from bs4 import BeautifulSoup
url = 'find the link above'
def get_youtube_link(link):
res = requests.get(link, headers={'User-Agent':'Mozilla/5.0'})
soup = BeautifulSoup(res.text,'lxml' )
youtube_link = soup.select_one("img[class='sleepy-load'][data-id^='video']")['data-original']
print(youtube_link )
if __name__ == '__main__':
get_youtube_link(url)
Output I'm getting:
//img.youtube.com/vi/tlgcDTLgNvg/default.jpg
As the link is not attached to that video so i could not show here how the link might look like.
This is how that video look like in that page:
How can i scrape that video link from that page?
Upvotes: 0
Views: 72
Reputation: 2130
If you are able to fetch //img.youtube.com/vi/tlgcDTLgNvg/default.jpg
here the tlgcDTLgNvg
is the youtube video id, the youtube link would be
video_id = "tlgcDTLgNvg"
youtube_link = https://youtu.be/{}.format(video_id)
Upvotes: 2