Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Python Beautiful Soup Example

python
from bs4 import BeautifulSoup

html = """
<html>
  <div class="target" style="color: #123434">Content</div>
</html>
"""

soup = BeautifulSoup(html, 'html.parser')
divs = soup.find_all('div', 'target')
div = divs[0]
style = div.attrs['style']

print(style)
results start

NOTE : The docs say you can use this :

style = div.attrs['style']

instead of this :

style = div['style']

but that doesn't work consistently for me.

I think that was because I was trying to do :

#+begin _ example if 'thing' in element : print('here') #+end _ example

and the [TODO: Code shorthand span ] check doesn't work there. So, I'm just using [TODO: Code shorthand span ] all the time for consistency.