【发布时间】:2017-01-27 17:14:24
【问题描述】:
我想设置max_chapter 并执行功能,直到章节号达到max_chapter。然后,书号加1,执行相同的函数,直到章节号达到max_chapter。
例如,Book 1 - Chapter 1~20,Book 原来是 Book 2 并做函数 Book 2 - Chapter 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)
【问题讨论】:
-
把它们放在一起是什么意思?
-
哦...你知道我想从第 1 册的第 1~20 章中抓取所有文本,然后转到第 2 册的第 1 章并做同样的事情。所以,我认为 str(chapter) 和 str(book) 都应该按顺序增加。没有?
标签: python python-2.7 python-3.x beautifulsoup python-requests