import bs4 html = """<div class="someClass"> <a href="href"> <img alt="some" src="some"/> </a> </div>""" soup = bs4.BeautifulSoup(html, "html.parser") # this will return src attrib from img tag that is inside 'a' tag soup.a.img['src'] >>> 'some' # if you have more then one 'a' tag for a in soup.find_all('a'): if a.img: print(a.img['src']) >>> 'some'
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter