Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resolving YouTube search links
#4
Ok I've spent hours sifting through the libraries and I'm still failing. I've simplified the script based on one of the libraries I found to help identify the issue.

It looks like the vids object is not working as expected. I've commented the response I get with attempts to print at various points.

Since vids ends up empty, how can I tell if the issue lies with my code or if there are no matching results in the soup? Or both lol.

from bs4 import BeautifulSoup as bs
import requests

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

r = requests.get(base + qstring)

page = r.text
soup = bs(page, 'html.parser')
# print(soup) #prints html
vids = soup.findAll('a', attrs={'class':'yt-uix-tile-link'}, limit=5)
# print(vids) prints []
videolist = []

for v in vids:
    tmp = 'https://www.youtube.com' + v['href']
    videolist.append(tmp)
    inc = 1
    inc += 1
    if inc > 5:
        break

print(videolist) # prints []
EDIT: Looks like this task can't be accomplished in this way due to JS being involved. Will look for alternative solutions.
Reply


Messages In This Thread
Resolving YouTube search links - by pythonnewbie138 - Jul-28-2020, 04:20 PM
RE: Resolving YouTube search links - by Larz60+ - Jul-28-2020, 04:28 PM
RE: Resolving YouTube search links - by pythonnewbie138 - Jul-31-2020, 09:46 PM
RE: Resolving YouTube search links - by Larz60+ - Aug-01-2020, 02:09 AM
RE: Resolving YouTube search links - by j.crater - Aug-01-2020, 08:08 AM
RE: Resolving YouTube search links - by j.crater - Aug-01-2020, 07:16 PM
RE: Resolving YouTube search links - by Axel_Erfurt - Aug-01-2020, 08:13 PM
RE: Resolving YouTube search links - by snippsat - Aug-02-2020, 12:00 AM
RE: Resolving YouTube search links - by snippsat - Aug-02-2020, 10:27 PM
RE: Resolving YouTube search links - by snippsat - Aug-04-2020, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  webscrapping links and then enter those links to scrape data kirito85 2 3,231 Jun-13-2019, 02:23 AM
Last Post: kirito85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020