Skip to content

Commit daef833

Browse files
authored
Added loop for more PacktPub pages to solve issue #26
Added loop for more PacktPub pages to solve issue #26 as a workaround for new PacktPub ebooks pages structure.
1 parent b9b7592 commit daef833

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

downloader.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,31 @@ def main(argv):
316316
if book_assets:
317317

318318
# get the list of books
319-
books_page = session.get("https://www.packtpub.com/account/my-ebooks", verify=True, headers=headers)
320-
books_tree = html.fromstring(books_page.content)
321-
book_nodes = books_tree.xpath("//div[@id='product-account-list']/div[contains(@class,'product-line unseen')]")
322-
323-
print('###########################################################################')
324-
print("FOUND {0} BOOKS: STARTING DOWNLOADS".format(len(book_nodes)))
325-
print('###########################################################################')
326-
327-
# loop through the books
328-
for book in book_nodes:
329-
330-
# download the book
331-
books_directory = os.path.join(root_directory, "books")
332-
download_book(book, books_directory, book_assets, session, headers)
333-
319+
page = 1
320+
books_page = session.get("https://www.packtpub.com/account/my-ebooks?page={0}".format(page), verify=True, headers=headers)
321+
pages_tree = html.fromstring(books_page.content)
322+
pages_nodes = pages_tree.xpath("//*[contains(@class,'solr-page-page-selector-page')]")
323+
pages_max = (len(pages_nodes)) + 1
324+
# added loop for the more PacktPub pages
325+
for page in range((pages_max)):
326+
page += 1
327+
url = 'https://www.packtpub.com/account/my-ebooks?page='
328+
url = (url + str(page))
329+
books_page = session.get(url, verify=True, headers=headers)
330+
books_tree = html.fromstring(books_page.content)
331+
book_nodes = books_tree.xpath("//div[@id='product-account-list']/div[contains(@class,'product-line unseen')]")
332+
333+
print('###########################################################################')
334+
print("FOUND {0} BOOKS: STARTING DOWNLOADS".format(len(book_nodes)))
335+
print('###########################################################################')
336+
337+
# loop through thpages
338+
for book in book_nodes:
339+
340+
# download the book
341+
books_directory = os.path.join(root_directory, "books")
342+
download_book(book, books_directory, book_assets, session, headers)
343+
334344
if video_assets:
335345

336346
# get the list of videos

0 commit comments

Comments
 (0)