次のコードで:
url ='http://lampspw.wallonie.be/dgo4/site_ipic/index.php/fiche/index?sortCol=2&sortDir=asc&start=0&nbElemPage=10&filtre=&codeInt=62121-INV-0018-02'
soup = BeautifulSoup(page.content, 'html.parser')
t = soup.find_all("div", attrs={'class':'panel-heading'})
lst = [x.text for x in t]
私が得る:
['\xa0Filtres complémentaires',
'\xa0Recherche dans les notices',
'Libellé(s)\xa0',
'Illustration(s)',
'Localisation',...]
部分文字列を使用してスープで直接特定のタグ(そのリストに含まれている)を検索する場合:
In [290]: soup.find_all("div", string=re.compile('Locali'))
Out[291]: [<div class="panel-heading">Localisation</div>]
前のタグの1つが見つかりました。しかし、私がそうするなら:
In :soup.find_all("div", string=re.compile('Libe'))
Out: []
誰かがここで問題を説明できますか?HTMLコード内にあると思いますが、見つかりません...
kcorlidyのおかげで:soup.find_all(string = re.compile( 'Libe'))が結果を取得します
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加