下記のPythonで書かれたコードのre.compile()関数の引数rの意味が知りたいです。ご教授願います。
Python3
1from bs4 import BeautifulSoup 2import re # 正規表現を使う時 --- (*1) 3 4html = """ 5<ul> 6 <li><a href="hoge.html">hoge</li> 7 <li><a href="https://example.com/fuga">fuga*</li> 8 <li><a href="https://example.com/foo">foo*</li> 9 <li><a href="http://example.com/aaa">aaa</li> 10</ul> 11""" 12soup = BeautifulSoup(html, "html.parser") 13# 正規表現でhrefからhttpsのものを抽出 --- (*2) 14li = soup.find_all(href=re.compile(r"^https://")) 15for e in li: print(e.attrs['href'])
また、このコードを実行した結果は下記になります。
bash
1$ python3 sel-re.py 2https://example.com/fuga 3https://example.com/foo
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/06/16 04:30
退会済みユーザー
2019/06/16 04:49