feat: only start from the beginning if --first is set
This commit is contained in:
parent
95b07cd802
commit
5b342f4667
23
main.py
23
main.py
|
|
@ -52,20 +52,21 @@ def fetch_page(
|
||||||
|
|
||||||
def fetch_comic(args):
|
def fetch_comic(args):
|
||||||
"""Download the requested comic pages to a local directory."""
|
"""Download the requested comic pages to a local directory."""
|
||||||
home_page = requests.get(args.domain)
|
page = requests.get(args.domain)
|
||||||
home_s = BeautifulSoup(home_page.text, "html.parser")
|
soup = BeautifulSoup(page.text, "html.parser")
|
||||||
|
|
||||||
out_dir = Path(os.getcwd()).joinpath(args.output)
|
out_dir = Path(os.getcwd()).joinpath(args.output)
|
||||||
|
|
||||||
first_url = home_s.find("a", rel=args.first).get("href")
|
if args.first:
|
||||||
if not first_url.startswith("https://"):
|
first_url = soup.find("a", rel=args.first).get("href")
|
||||||
first_url = args.domain + first_url
|
if not first_url.startswith("https://"):
|
||||||
next_page = requests.get(first_url)
|
first_url = args.domain + first_url
|
||||||
next_soup = BeautifulSoup(next_page.text, "html.parser")
|
page = requests.get(first_url)
|
||||||
|
soup = BeautifulSoup(page.text, "html.parser")
|
||||||
try:
|
try:
|
||||||
next_url = next_soup.find("a", rel=args.next).get("href")
|
next_url = soup.find("a", rel=args.next).get("href")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print(next_soup.find("a"))
|
print(soup.find("a"))
|
||||||
i = 1
|
i = 1
|
||||||
while i < args.end:
|
while i < args.end:
|
||||||
begin = args.begin if args.begin else 1
|
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)"
|
"--img", default=None, help="html 'id' tag of the comic's img element(s)"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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(
|
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(
|
parser.add_argument(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue