Snippets Collections
In [8]: from bs4 import BeautifulSoup

In [9]: from selenium import webdriver

In [10]: driver = webdriver.Firefox()

In [11]: driver.get('')

In [12]: html = driver.page_source

In [13]: soup = BeautifulSoup(html)

In [14]: for tag in soup.find_all('title'):
   ....:     print tag.text
Hacker News
import bs4

html = """<div class="someClass">
    <a href="href">
        <img alt="some" src="some"/>

soup = bs4.BeautifulSoup(html, "html.parser")

# this will return src attrib from img tag that is inside 'a' tag

>>> 'some'

# if you have more then one 'a' tag
for a in soup.find_all('a'):
    if a.img:

>>> 'some'

Sun Oct 25 2020 06:36:31 GMT+0000 (Coordinated Universal Time)

#python #beautifulsoup

Sun Oct 25 2020 06:35:44 GMT+0000 (Coordinated Universal Time)

#python #beautifulsoup

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension