From cf119599702c6d66e50bbf8e6c5836b0902d5792 Mon Sep 17 00:00:00 2001 From: cryzed Date: Sun, 8 Jun 2014 15:48:10 +0200 Subject: [PATCH] Backported some changes from the http://nocturnal-light.net/ adapter --- .../adapters/adapter_spikeluvercom.py | 17 +++++++++++------ .../adapters/adapter_voracity2eficcom.py | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/fanficdownloader/adapters/adapter_spikeluvercom.py b/fanficdownloader/adapters/adapter_spikeluvercom.py index 6918f09..3441b4a 100644 --- a/fanficdownloader/adapters/adapter_spikeluvercom.py +++ b/fanficdownloader/adapters/adapter_spikeluvercom.py @@ -12,6 +12,16 @@ def getClass(): return SpikeluverComAdapter +# yields Tag _and_ NavigableString siblings from the given tag. The +# BeautifulSoup findNextSiblings() method for some reasons only returns either +# NavigableStrings _or_ Tag objects, not both. +def _yield_next_siblings(tag): + sibling = tag.nextSibling + while sibling: + yield sibling + sibling = sibling.nextSibling + + class SpikeluverComAdapter(BaseSiteAdapter): SITE_ABBREVIATION = 'slc' SITE_DOMAIN = 'spikeluver.com' @@ -107,11 +117,7 @@ class SpikeluverComAdapter(BaseSiteAdapter): contents = [] keep_summary_html = self.getConfig('keep_summary_html') - # For some reason span_tag.findNextSiblings() only returns tags - # instead both NavigableString objects _and_ Tag objects as - # documented, so navigate manually - sibling = span_tag.nextSibling - while sibling: + for sibling in _yield_next_siblings(span_tag): if isinstance(sibling, BeautifulSoup.Tag): # Encountered next label, break. Not as bad as other # e-fiction sites, let's hope this is enough for proper @@ -125,7 +131,6 @@ class SpikeluverComAdapter(BaseSiteAdapter): contents.append(''.join(sibling(text=True))) else: contents.append(sibling) - sibling = sibling.nextSibling # Remove the preceding break line tag and other crud contents.pop() diff --git a/fanficdownloader/adapters/adapter_voracity2eficcom.py b/fanficdownloader/adapters/adapter_voracity2eficcom.py index 9b18245..3b59935 100644 --- a/fanficdownloader/adapters/adapter_voracity2eficcom.py +++ b/fanficdownloader/adapters/adapter_voracity2eficcom.py @@ -12,6 +12,16 @@ def getClass(): return Voracity2EficComAdapter +# yields Tag _and_ NavigableString siblings from the given tag. The +# BeautifulSoup findNextSiblings() method for some reasons only returns either +# NavigableStrings _or_ Tag objects, not both. +def _yield_next_siblings(tag): + sibling = tag.nextSibling + while sibling: + yield sibling + sibling = sibling.nextSibling + + class Voracity2EficComAdapter(BaseSiteAdapter): SITE_ABBREVIATION = 'voe' SITE_DOMAIN = 'voracity2.e-fic.com' @@ -147,11 +157,7 @@ class Voracity2EficComAdapter(BaseSiteAdapter): contents = [] keep_summary_html = self.getConfig('keep_summary_html') - # For some reason span_tag.findNextSiblings() only returns tags - # instead both NavigableString objects _and_ Tag objects as - # documented, so navigate manually - sibling = b_tag.nextSibling - while sibling: + for sibling in _yield_next_siblings(b_tag): if isinstance(sibling, BeautifulSoup.Tag): # Encountered next label, break. This method is the # safest and most reliable I could think of. Blame @@ -167,7 +173,6 @@ class Voracity2EficComAdapter(BaseSiteAdapter): contents.append(''.join(sibling(text=True))) else: contents.append(sibling) - sibling = sibling.nextSibling # Remove the preceding break line tag and other crud contents.pop()