Fix CyanideAndHappiness (fixes #227)

This commit is contained in:
Tobias Gruetzmacher 2023-10-08 20:41:39 +02:00
parent 5f2a3cc7cf
commit 5de53cb4b4
No known key found for this signature in database

View file

@ -1,8 +1,8 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # SPDX-FileCopyrightText: © 2004 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012-2014 Bastian Kleineidam # SPDX-FileCopyrightText: © 2012 Bastian Kleineidam
# Copyright (C) 2015-2022 Tobias Gruetzmacher # SPDX-FileCopyrightText: © 2015 Tobias Gruetzmacher
# Copyright (C) 2019-2020 Daniel Ring # SPDX-FileCopyrightText: © 2019 Daniel Ring
from re import compile, escape from re import compile, escape
from typing import List from typing import List
@ -460,25 +460,13 @@ class CutLoose(_ParserScraper):
return '%s-%s-%s_%s' % (postDate[1], postDate[2], postDate[3], filename) return '%s-%s-%s_%s' % (postDate[1], postDate[2], postDate[3], filename)
class CyanideAndHappiness(_BasicScraper): class CyanideAndHappiness(ParserScraper):
url = 'https://explosm.net/comics/' url = 'https://explosm.net/'
stripUrl = url + '%s/' imageSearch = '//div[@id="comic"]//div[contains(@class,"ComicImage")]/span//img'
firstStripUrl = stripUrl % '15' prevSearch = '//div[@type="comic"]//a[*[local-name()="svg" and @rotate="180deg"]]'
imageSearch = compile(tagre("img", "src", r'(.*files.explosm.net/[^/]+/[^"]+)', before="main-comic")) nextSearch = '//div[@type="comic"]//a[*[local-name()="svg" and @rotate="0deg"]]'
prevSearch = compile(tagre("a", "href", r'(/comics/\d+/)', after="nav-previous")) starter = bounceStarter
nextSearch = compile(tagre("a", "href", r"(/comics/\d+/)", after="nav-next")) namer = joinPathPartsNamer((), range(-4, 0))
help = 'Index format: n (unpadded)'
def shouldSkipUrl(self, url, data):
"""Skip pages without images."""
return "/comics/play-button.png" in data[0]
def namer(self, image_url, page_url):
imgname = image_url.split('/')[-1]
# only get the first 100 chars for the image name
imgname = imgname[:100]
imgnum = page_url.split('/')[-2]
return '%s_%s' % (imgnum, imgname)
class CynWolf(_ParserScraper): class CynWolf(_ParserScraper):