Update adapter_asianfanficscom.py

This commit is contained in:
oh45454545 2021-09-08 15:55:02 +02:00 committed by Jim Miller
parent 1082dc5417
commit 03d030feab

View file

@ -246,13 +246,8 @@ class AsianFanFicsComAdapter(BaseSiteAdapter):
data = self.get_request(url)
soup = self.make_soup(data)
content = soup.find('div', {'id': 'user-submitted-body'})
try:
# <script>var postApi = "https://www.asianfanfics.com/api/chapters/4791923/chapter_46d32e413d1a702a26f7637eabbfb6f3.json";</script>
jsonlink = soup.find('script',string=re.compile(r'/api/chapters/[0-9]+/chapter_[0-9a-z]+.json')).get_text().split('"')[1] # grabs url from quotation marks
chap_json = json.loads(self.get_request(jsonlink))
content = self.make_soup(chap_json['post']).find('body') # BS4 adds <html><body> if not present.
content.name='div' # change body to a div.
if self.getConfig('inject_chapter_title'):
# the dumbest workaround ever for the abbreviated chapter titles from before
logger.debug("Injecting full-length chapter title")
@ -263,7 +258,3 @@ class AsianFanFicsComAdapter(BaseSiteAdapter):
return self.utf8FromSoup(url,newTitle)
else:
return self.utf8FromSoup(url,content)
except Exception as e:
logger.debug("json lookup failed, going on with HTML chapter")
content = soup.find('div', {'id': 'user-submitted-body'})
return self.utf8FromSoup(url,content)