Jul-31-2020, 09:46 PM
(This post was last modified: Jul-31-2020, 09:46 PM by pythonnewbie138.)
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
Since
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.