There is a piece of HTML code of the page that I parse:

<td> <a class="soup" href="link">Борщ</a> </td> <td> <a class="soup" href="link">Рассольник</a> <br> <img src="/any.gif"> </br> </td> <td> <a class="soup" href="link">Грибной</a> </td> <td> <a class="soup" href="link">Щи</a> <br> <img src="/any.gif"> </br> </td> <td> <a class="soup" href="link">Молочный</a> </td> 

Question: how to collect all only those that are <br> <img> ?
How to collect all <td> in which there is <br> <img> ? (using BeautifulSoup )

  • It does not happen at all. - Qwertiy
  • 2
    <br/> this is an empty element in html — it cannot contain anything. BeautifulSoup of course can search for arbitrary criteria. - jfs
  • one
    if the find result suits you, you can find_all use - jfs
  • one
    think: if you know how to get the result for one element, then how to get a list of results from the list of input values? Why do you expect the attribute list to return attribute values ​​for list items? Instead, try the результат = [элемент.атрибут for элемент in список] - jfs

1 answer 1

 for img in soup.find_all('img', {'src': '/any.gif'}): if img.findPreviousSibling('a') is not None: a=img.findPreviousSibling('a') print(a) 

The answer from the English. stackoverflow