I got a question for HTML parsing using python.
I'm trying to get the attribute key and value to use if fomular in python.
<!DOCTYPE HTML>
<html>
<body>
<p dir="ltr" class="FM_title_0">Test Color</p>
</body>
</html>
and this is code that i am making as follow
with open("C:\\file") as fp:
soup = BeautifulSoup(fp, "html.parser")
tag = soup.p
if tag['class'] == 'FM_title_0' :
print('aaa')
but the result shows nothing. i figure out that tag['class'] is not able to read 'FM_title_0'. why does it not read 'FM_title_0' ??
additionally, when i run this code below
with open("C:\\file") as fp:
soup = BeautifulSoup(fp, "html.parser")
tag = soup.p
print(tag['class'])
it shows ['FM_title_0']. but please look this one below
with open("C:\\file") as fp:
soup = BeautifulSoup(fp, "html.parser")
tag = soup.p
print(tag['dir'])
this result shows ltr.
Is there any difference between [xxx] and xxx when read attribute's value ?