CSS SELECTORS
只支持CSS syntax,但您可以使用string
属性按标签内容进行搜索:
soup.find(string=re.compile(r"HO\s?#",re.IGNORECASE))
soup.find_all(string=re.compile(r"HO\s?#",re.IGNORECASE))
findNextSibling('td')
步回到parent
你所定位的物体.
Example
from bs4 import BeautifulSoup
import re
soup = BeautifulSoup('<table><tr><td>HO #</td><td>I am the next sibling</td></tr><tr><td>HO #</td></tr><tr><td>ho#</td><td>I am the next sibling</td></tr></table>')
for e in soup.find_all(string=re.compile(r"HO\s?#",re.IGNORECASE)):
print(e)
print(e.parent.findNextSibling('td'))
HO #
<td>I am the next sibling</td>
HO #
None
ho#
<td>I am the next sibling</td>