[naver] simplify code + add test

This commit is contained in:
Mike Fährmann
2024-03-05 23:18:20 +01:00
parent f64fb8f239
commit a8d3efbb99
2 changed files with 34 additions and 11 deletions

View File

@@ -10,7 +10,6 @@
from .common import GalleryExtractor, Extractor, Message
from .. import text
from urllib.parse import unquote
class NaverBase():
@@ -63,16 +62,13 @@ class NaverPostExtractor(NaverBase, GalleryExtractor):
return data
def images(self, page):
return [
(unquote(url, encoding="EUC-KR")
.replace("://post", "://blog", 1)
.partition("?")[0], None)
if "\ufffd" in unquote(url)
else
(url.replace("://post", "://blog", 1)
.partition("?")[0], None)
for url in text.extract_iter(page, 'data-lazy-src="', '"')
]
results = []
for url in text.extract_iter(page, 'data-lazy-src="', '"'):
url = url.replace("://post", "://blog", 1).partition("?")[0]
if "\ufffd" in text.unquote(url):
url = text.unquote(url, encoding="EUC-KR")
results.append((url, None))
return results
class NaverBlogExtractor(NaverBase, Extractor):