Ok, so I am trying to write a code that will find the attributes in a html tag using lists and splitting them up. Unfortunately its giving me a hard time with the added quotation marks.
def find_attribute_value(html_tag, att):
'''Return the value of attribute att (a str) in the str html_tag.
Return None if att doesn't occur in html_tag.
'''
words = html_tag.split(" ")
#this is me trying to split up the initial html tag.
omgs= str (words)
# then trying to convert it into a string because it wouldn't let me split it up further otherwise :(
list2 = omgssss.split()
# then I split it up again
for word in list2:
second_split = word.split("=")
#and again because I needed to separate the attributes from the equal sign.
#this is what I want to do with my code, but I can't implement it because my code looks like it was written by a 4 year old. I want to be able to recognize the attributed value and call the value.
if att == item in list:
print list[att]
print second_split
my example that I was testing it out on was this html tag:
find_attribute_value('<img align=top src="photos/horton.JPG" alt="Image of StG instructor (Diane Horton)">', "src")
and i'm trying to find the att being src
which would bring up "photos/horton.JPG"
but obviously it doesn't