Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- label_tag = row.find(class_='Label')
- print(label_tag)
- <a class="Label" href="_link_">_text_</a>
- <class 'bs4.element.Tag'>
- tag_link = label_tag['href']
- print(tag_link)
- TypeError: 'NoneType' object is not subscriptable
- import bs4
- text = '''<a class="Label" href="_link_">_text_</a>'''
- soup = bs4.BeautifulSoup(text)
- link = soup.find("a",{"class":"Label"})
- print (link["href"])
- _link_
- if tag_link = label_tag.get('href'):
- print(tag_link)
- else:
- print("there is no class of 'Label' or no attribute of 'href'! ")
Add Comment
Please, Sign In to add comment