I'm trying to get the img alt portion of the element, but for some reason it will not register as an attribute of the element even though it is included in the printout of the string. How can I pull the img alt too (I need the text that says Boxed Warning but I'm not sure how to fix/make my code get it)?
page=requests.get('http://www.drugs.com/labeling-changes/May-2016.html')
noStarchSoup=bs4.BeautifulSoup(page.text, "html.parser")
elems=noStarchSoup.select('tr td > a')
print(elems[0].getText())
print(str(elems[1]))
print(elems[1].get('alt'))
print(elems[1].attrs)
Anaprox
<a href="/labeling-changes/May-2016/anaprox-naproxen-4321.html" rel="nofollow"><img alt="Boxed Warning" height="16" src="/img/icons/exclamation.png" title="Changes have been made to the Boxed Warning section of the safety label." width="16"/></a>
None
{'href': '/labeling-changes/May-2016/anaprox-naproxen-4321.html', 'rel':['nofollow']}