From 5b342f4667c00b2ea1d62683a3c497c94fdb4940 Mon Sep 17 00:00:00 2001 From: missytake Date: Mon, 24 Nov 2025 21:44:06 +0100 Subject: [PATCH] feat: only start from the beginning if --first is set --- main.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 7d9b65f..fd798af 100644 --- a/main.py +++ b/main.py @@ -52,20 +52,21 @@ def fetch_page( def fetch_comic(args): """Download the requested comic pages to a local directory.""" - home_page = requests.get(args.domain) - home_s = BeautifulSoup(home_page.text, "html.parser") + page = requests.get(args.domain) + soup = BeautifulSoup(page.text, "html.parser") out_dir = Path(os.getcwd()).joinpath(args.output) - first_url = home_s.find("a", rel=args.first).get("href") - if not first_url.startswith("https://"): - first_url = args.domain + first_url - next_page = requests.get(first_url) - next_soup = BeautifulSoup(next_page.text, "html.parser") + if args.first: + first_url = soup.find("a", rel=args.first).get("href") + if not first_url.startswith("https://"): + first_url = args.domain + first_url + page = requests.get(first_url) + soup = BeautifulSoup(page.text, "html.parser") try: - next_url = next_soup.find("a", rel=args.next).get("href") + next_url = soup.find("a", rel=args.next).get("href") except AttributeError: - print(next_soup.find("a")) + print(soup.find("a")) i = 1 while i < args.end: begin = args.begin if args.begin else 1 @@ -94,10 +95,10 @@ def cli(): "--img", default=None, help="html 'id' tag of the comic's img element(s)" ) parser.add_argument( - "--first", default=None, help="html 'id' tag of the 'first comic' button" + "--first", default=None, help="html 'rel' tag of the 'first comic' button" ) parser.add_argument( - "--next", default=None, help="html 'id' tag of the 'next comic' button" + "--next", default=None, help="html 'rel' tag of the 'next comic' button" ) parser.add_argument(