Я пытаюсь получить элементы в HTML-документе, которые содержат следующий шаблон текста: #\S {11}
<h2> this is cool #12345678901 </h2>
Итак, предыдущее совпадало бы с помощью:
soup('h2',text=re.compile(r' #\S{11}'))
И результаты будут примерно такими:
[u'blahblah #223409823523', u'thisisinteresting #293845023984']
Я могу получить весь текст, который соответствует (см. строку выше). Но я хочу, чтобы родительский элемент текста соответствовал, поэтому я могу использовать это как отправную точку для перемещения по дереву документов. В этом случае я бы хотел, чтобы все элементы h2 возвращались, а не текст.
Идеи?