キーテキストのラッパーを取得しますか?例えば、HTMLで:Python + BeautifulSoup:テキストに基づいてHTMLからラッパーを取り除くには?
…
<div class=“target”>chicken</div>
<div class=“not-target”>apple</div>
…
によってテキスト「鶏」に基づいて、バック<div class=“target”>chicken</div>
を取得したいと思います。
import requests
from bs4 import BeautifulSoup
req = requests.get(url).txt
soup = BeautifulSoup(r, ‘html.parser’)
そして、ちょうど私が探していますラッパーを見つけるために、利用可能なすべてのdiv
を通じてsoup.find_all(‘div’,…)
とループを行うに持つ:
は現在、HTMLを取得するために、次があります。
div
をループせずに、定義されたテキストに基づいてHTMLでラッパーをフェッチする適切かつ最適な方法は何でしょうか?
ありがとうございます。受け入れてください/ upvote答えてください!
https://stackoverflow.com/a/31959218/4387299 – internety
@internety Gave 'soup.find_all( 'div'、string = 'chicken')'は試みますが、空の配列を返します。 –
中括弧を使用しない –