Guest User

Untitled

a guest
Jul 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. label_tag = row.find(class_='Label')
  2. print(label_tag)
  3.  
  4. <a class="Label" href="_link_">_text_</a>
  5.  
  6. <class 'bs4.element.Tag'>
  7.  
  8. tag_link = label_tag['href']
  9. print(tag_link)
  10.  
  11. TypeError: 'NoneType' object is not subscriptable
  12.  
  13. import bs4
  14. text = '''<a class="Label" href="_link_">_text_</a>'''
  15. soup = bs4.BeautifulSoup(text)
  16. link = soup.find("a",{"class":"Label"})
  17. print (link["href"])
  18.  
  19. _link_
  20.  
  21. if tag_link = label_tag.get('href'):
  22. print(tag_link)
  23. else:
  24. print("there is no class of 'Label' or no attribute of 'href'! ")
Add Comment
Please, Sign In to add comment