I'm getting a string by scraping a certain website, then I'm trying to check if the first value of that string (in this case it's " <h2>maanantai 10.1.</h2> " contains the letter 'a'. If it does (like it does) - print 'YES'.
For some reason which I don't understand it just doesn't work.
import urllib.request
from bs4 import BeautifulSoup
url = 'https://kouluruoka.fi/menu/kouvola_koulujenruokalista'
request = urllib.request.Request(url)
content = urllib.request.urlopen(request)
parse = BeautifulSoup(content, 'html.parser')
h2_elements = parse.find_all('h2')
first_value_in_string = h2_elements[1]
# this one prints " <h2>maanantai 10.1.</h2> " as it should
print(first_value_in_string)
# this one should check if the value (first_value_in_string) contains the letter 'a' and if it does then print 'YES' but for some reason it doesnt
if 'a' in first_value_in_string:
print('YES')
'a' in " <h2>maanantai 10.1.</h2> "returns True, so are you sure about your debugging, for example isfirst_value_in_stringactually a string?