1
の背後にある正見て、私はこのコードを修正し、Pythonの正規表現、
sre_constants.error: look-behind requires fixed-width pattern
を得続けるためにしようとしていますが、私が何をしようとしています何...このエラーを取り除く上で私を助けてください番号を取得することですこれは変数w
である単語の直後にある変数w2
です。
import requests
import re
import bs4
def verse(book, chapter):
html = requests.get("http://www.holybible.or.kr/B_NIV/cgi/bibleftxt.php?VR=NIV&VL={}&CN={}&CV=99"
.format(book, chapter)).text
bs = bs4.BeautifulSoup(html, 'html5lib')
ol = bs.findAll('ol')
section_cnt = int(ol[-1].attrs['start']) + len(ol[-1].findAll('li')) - 1
w = re.search(r'(?<=height=12>\s<b>)(\d+\s)?[a-zA-Z]+\s[0-9]+', html).group()
w2 = re.search(r'(?<=height=12>\s<b>(\d+\s)?[a-zA-Z])+\s[0-9]+', html).group()
print(w, 'has', w2, 'chapters', section_cnt, 'verses')
if __name__ == '__main__':
verse(1, 27)
[re](https://docs.python.org/2/library/re.html)のドキュメントから、 '()'は特殊文字です。あなたが一致するものがcontains()なら '\'でエスケープする必要があります。 –