本文整理匯總了Python中book.Book.add_chapter方法的典型用法代碼示例。如果您正苦於以下問題:Python Book.add_chapter方法的具體用法?Python Book.add_chapter怎麽用?Python Book.add_chapter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類book.Book
的用法示例。
在下文中一共展示了Book.add_chapter方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_books
# 需要導入模塊: from book import Book [as 別名]
# 或者: from book.Book import add_chapter [as 別名]
def load_books(self):
print("Loading books...")
if self.has_books:
accordion = self.index_soup.find('div', attrs={'id': 'accordion'})
panels = accordion.find_all('div', attrs={'class': 'panel'})
for panel in panels:
book = Book()
book.number = int(panel.find('h4').find('span', attrs={'class': 'book'}).get_text())
if self.skip_first:
book.number -= 1
if book.number == 0:
continue
book.number = str(book.number)
if book.number not in self.chosen_books:
continue
book.title = panel.find('h4').find('span', attrs={'class': 'title'}).find('a').get_text().strip()
links = panel.find('div', attrs={'class': 'panel-body'}).find_all('a')
for link in links:
book.add_chapter(Chapter(url=link.get('href'), title=link.get_text().strip()))
self.books.append(book)
print("Book {} done!".format(book))