Home Python 3.5 not cooperating with BeautifulSoup and variables
Reply: 0

Python 3.5 not cooperating with BeautifulSoup and variables

user1090 Published in May 25, 2018, 7:13 am

I'm trying to write a program that can check whether or not a YouTube video is in the music category or not. I have written some code but its almost as if Python is "lying" to me. Here is the code

>>> from bs4 import BeautifulSoup
>>> from urllib.request import urlopen
>>> url = "https://www.youtube.com/watch?v=LXuNNqoo1WQ"
>>> html = urlopen(url).read()
>>> soup = BeautifulSoup(html, "html.parser")
>>> tags = soup.find_all(class_="content watch-info-tag-list")
>>> hasmusictag = 'href="/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ">Music</a>' in 
>>> print(hasmusictag)
>>> print(tags[0])
<ul class="content watch-info-tag-list">
<li><a class=" yt-uix-sessionlink spf-link " data-
sessionlink="ei=udFWWrG5EYqB8wSag5rgCg" href="/channel/UC-9-

As you can see, hasmusictag should return true, but it is returning false. I have no idea why. All help is appreciated!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.549585 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO