Python Forum

Full Version: Doing some tests with SoupStrainer
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello dear pythonistas - hello dear python-experts,

hope everything is all right and youre well. i am doing some tests with SoupStrainer


import requests 
from bs4 import BeautifulSoup, SoupStrainer

content = requests.get('https://www.google.com').content

for link in BeautifulSoup(content, parse_only=SoupStrainer('a')):
  if hasattr(link, "href"):
    print(link['href'])
note: i only want to have the links that are in bold tags



all with a bold tag:

<li><b><a href="linkitem_a.html">linkitem_a</a></b> {bla_bla_a} (bla_bla_a), apple_crumble
</li>
<li><a href="linkitem_b.html">linkitem_b</a> {bla_bla_b} (bla_bla_b), apple_crumble
</li>
<li><b><a href="linkitem_c.html">linkitem_c</a></b> {bla_bla_c} (bla_bla_c), apple_crumble
how to implement this condition in the souStrainer-code-parser!?