我想設置max_chapter
並執行功能,直到章號達到max_chapter
。然後,書號增加1並通過相同的功能,直到章號達到max_chapter
。在這種情況下如何將兩個「while」循環放在一起?
例如,圖書1 - 第1章〜20,書原來是2冊,做書的功能2 - 第1章〜20,...等等。
這裏是我的代碼的一部分,我有一個問題:
import requests
from bs4 import BeautifulSoup
import operator
def start(max_book):
word_list = []
book = 1
chapter = 1
while book <= max_book:
url = ('http://www.holybible.or.kr/B_NIV/cgi/bibleftxt.php?VR=NIV&VL='
+ str(book) + '&CN=' + str(chapter) + '&CV=99')
while chapter <= 1:
source_code = requests.get(url).text
soup = BeautifulSoup(source_code, "html.parser")
for bible_text in soup.findAll('font', {'class': 'tk4l'}):
content = bible_text.get_text()
words = content.lower().split()
for each_word in words:
word_list.append(each_word)
chapter += 1
else:
book += 1
print(word_list)
start(1)
你是什麼把它們放在一起是什麼意思? – Sayse
哦......你知道我想抓住書1中第1〜20章的所有文本,並轉到第2章的第1章,並做同樣的事情。所以,我認爲str(章節)和str(書)都應該按順序增加。沒有? –