From 3bfc3873945692eb0fcd4d23aa6c028a76118e3b Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Thu, 27 Sep 2018 01:49:03 +0200 Subject: [PATCH] Updates to PACKT claimer/downloader. --- packtclaim.py | 6 ++++-- packtdl.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packtclaim.py b/packtclaim.py index c32b25a..bf76905 100755 --- a/packtclaim.py +++ b/packtclaim.py @@ -36,9 +36,11 @@ g.doc.text_assert('"sid":') g.doc.text_assert('Claim Your Free eBook') claim_book = g.doc.select('//div[@class="dotd-title"]/h2').text() print("Book: {}".format(claim_book)) -claim_url = g.doc.select('//a[@class="twelve-days-claim"]/@href').text() +claim_url = g.doc.select('//form[@id="free-learning-form"]/@action').text() print("Claim URL: {}".format(claim_url)) -g.go(claim_url) +g.doc.choose_form(id='free-learning-form') +g.doc.submit() +#g.go(claim_url) g.doc.save('/tmp/free-learning-after-claim.html') g.doc.text_assert('

My eBooks

') print("Claim successful.") diff --git a/packtdl.py b/packtdl.py index f7c431c..ebef7ae 100755 --- a/packtdl.py +++ b/packtdl.py @@ -147,7 +147,7 @@ else: print("Found {:d} ebooks.".format(len(all_books))) -if opts["idx_end"] or opts["count"]: +if opts["idx_start"] > 1 or opts["idx_end"] or opts["count"]: # Some range given: Download books idx_start = opts["idx_start"] if idx_start < 1: @@ -158,7 +158,7 @@ if opts["idx_end"] or opts["count"]: elif opts["count"]: idx_end = idx_start + opts["count"] - 1 else: - idx_end = idx_start + idx_end = len(all_books) if idx_end < idx_start: idx_end = idx_start