Select all div siblings by using BeautifulSoup
问题 I have an html file which has a structure like the following: <div> </div <div> </div> <div> <div> </div> <div> </div> <div> </div> <div> <div> <div> </div> </div> I would like to select all the siblings div without selecting nested div in the third and fourth block. If I use find_all() I get all the divs. 回答1: You can find direct children of the parent element: soup.select('body > div') to get all div elements under the top-level body tag. You could also find the first div , then grab all