feat: only start from the beginning if --first is set
This commit is contained in:
parent
95b07cd802
commit
5b342f4667
19
main.py
19
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 args.first:
|
||||
first_url = soup.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")
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue