I have the following html and I am using bs4 beautiful soup in python 3 to extract all hrefs from links that are located inside a specific tag: . It should not be important if there might me more than one or no link nested in the . Furthermore, there would be another step where I filter out links that don't have the "base.html" ending.
<article>
<a href='link/base.html'>click me!</a>
</article>
...
<article>
<a href='link2/base.html'>click me!</a>
</article>
...
<article>
<a href='link3/base.html'>click me!</a>
</article>
This is my code
page = bs4.BeautifulSoup(source, 'html.parser')
articles = page.find_all(name="article")
article_links = map(lambda article: article.a, articles)
article_links = map(lambda tag: tag.get('href'), article_links)
article_links = filter(lambda link: 'base.html' in link, article_links)
article_links = map(lambda link: url + link, article_links)
However, this results in an
AttributeError: 'NoneType' object has no attribute 'get''
at the .get('href') part in line 4. Other variations result in different errors. It needs to be lambda functions. Preferably, I would also like to combine the first two lambda functions into one.