-1
HTML内のタグのインデックスを見つけるのpython文字列
<div class="productDescriptionWrapper">
<p>A worm worth getting your hands dirty over. With over six feet of crawl space, Playhut’s Wiggly Worm is a brightly colored and friendly play structure.
</p>
<ul>
<li>6ft of crawl through fun</li>
<li>18” diameter for easy crawl through</li>
<li>Bright colorful design</li>
<li>Product Measures: 18""Diam x 60""L</li>
<li>Recommended Ages: 3 years & up<br /> </li>
</ul>
<p><strong>Intended for Indoor Use</strong></p>
コード
def GetBullets(self, Soup):
bulletList = []
bullets = str(Soup.findAll('div', {'class': 'productDescriptionWrapper'}))
bullets_re = re.compile('<li>(.*)</li>')
bullets_pat = str(re.findall(bullets_re, bullets))
index = bullets_pat.findall('</li>')
print index
方法p
タグとli
タグを抽出する
<コメントが削除されました> –
注意してください。これらのタグは相互に入れ子にすることができます。つまり、REは開始タグと終了タグを適切に一致させません。だから、(おそらく)BeautifulSoupのようなパーサを使うべきです。 –
あなたはBeautifulSoupを使ってdivを見つけてそれを放棄し、文字列を正規表現で解析しようとしました。私は、あなたがBeautifulSoupに全面的にこだわることをお勧めします。 – sgallen