Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to web scrap links from top 10 trending videos on youtube, but every time I run my program i get links to stuff about youtube (ads, copyright, policies.....).

What I have tried:

This is the code that i wrote:
import bs4
import requests
res=requests.get("https://www.youtube.com/feed/trending")
soup=bs4.BeautifulSoup(res.text,'html.parser')
for link in soup.find_all('a', href=True):
print(link['href'])
Posted
Updated 16-Oct-20 9:51am
Comments
ZurdoDev 16-Oct-20 15:38pm    
You have to write code to remove the other stuff. Or see if someone has already done it and posted sample code.
Filip Mrsovic 16-Oct-20 15:41pm    
I know how to remove the other stuff, but the thing is, i don't get links of videos at all, and I searched to see if someone had already done it, but i couldn't find anything, still thanks.....
Dave Kreskowiak 16-Oct-20 16:07pm    
You have to go look at the page source. You're code was written under the assumption that every link for a video is an A tag. They're not. I think you'll be surprised at what you find.
Filip Mrsovic 16-Oct-20 16:10pm    
Thank you , i will look it up.....

1 solution

Start by looking at what your get request actually returns: then start designing code to extract the info you want.

You can't just assume that what it returns is what you want: you have to look at what is available and work with that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900