ATTRIBUTE SEARCHING - find_all with attributes
Python
#!/usr/bin/env python3
"""ATTRIBUTE SEARCHING - find_all with attributes"""
from bs4 import BeautifulSoup
html = """
<html><body>
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Login">
<a href="/page" target="_blank">Link 1</a>
<a href="/other">Link 2</a>
</body></html>
"""
soup = BeautifulSoup(html, 'html.parser')
print("Attribute Searching:")
text_inputs = soup.find_all('input', type='text')
print(f" text inputs: {len(text_inputs)}")
blank_links = soup.find_all('a', target='_blank')
print(f" _blank links: {[a['href'] for a in blank_links]}")
named_inputs = soup.find_all('input', attrs={'name': True})
print(f" Named inputs: {[i['name'] for i in named_inputs]}")