How would I, using BeautifulSoup, search for tags containing ONLY the attributes I search for?
For example, I want to find all
As explained on the BeautifulSoup documentation You may use this : EDIT : To return tags that have only the valign="top" attribute, you can check for the length of the tag That returns :
soup = BeautifulSoup(html)
results = soup.findAll("td", {"valign" : "top"})
attrs property :from BeautifulSoup import BeautifulSoup
html = '..... \
....... \
..... '
soup = BeautifulSoup(html)
results = soup.findAll("td", {"valign" : "top"})
for result in results :
if len(result.attrs) == 1 :
print result
.....