[azurelanewiki] prevent Anubis challenge
This commit is contained in:
@@ -33,9 +33,11 @@ class WikimediaExtractor(BaseExtractor):
|
||||
|
||||
self.per_page = self.config("limit", 50)
|
||||
|
||||
if useragent := self.config_instance("useragent"):
|
||||
self.useragent = useragent
|
||||
|
||||
def _init(self):
|
||||
api_path = self.config_instance("api-path")
|
||||
if api_path:
|
||||
if api_path := self.config_instance("api-path"):
|
||||
if api_path[0] == "/":
|
||||
self.api_url = self.root + api_path
|
||||
else:
|
||||
@@ -110,14 +112,12 @@ class WikimediaExtractor(BaseExtractor):
|
||||
data = self.request_json(url, params=params)
|
||||
|
||||
# ref: https://www.mediawiki.org/wiki/API:Errors_and_warnings
|
||||
error = data.get("error")
|
||||
if error:
|
||||
if error := data.get("error"):
|
||||
self.log.error("%s: %s", error["code"], error["info"])
|
||||
return
|
||||
# MediaWiki will emit warnings for non-fatal mistakes such as
|
||||
# invalid parameter instead of raising an error
|
||||
warnings = data.get("warnings")
|
||||
if warnings:
|
||||
if warnings := data.get("warnings"):
|
||||
self.log.debug("MediaWiki returned warnings: %s", warnings)
|
||||
|
||||
try:
|
||||
@@ -187,6 +187,7 @@ BASE_PATTERN = WikimediaExtractor.update({
|
||||
"root": "https://azurlane.koumakan.jp",
|
||||
"pattern": r"azurlane\.koumakan\.jp",
|
||||
"api-path": "/w/api.php",
|
||||
"useragent": "Googlebot-Image/1.0",
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user