diff options
| -rw-r--r-- | newsdiff/core/parsers/ynet.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/newsdiff/core/parsers/ynet.py b/newsdiff/core/parsers/ynet.py index 769d238..995e7a2 100644 --- a/newsdiff/core/parsers/ynet.py +++ b/newsdiff/core/parsers/ynet.py @@ -26,14 +26,20 @@ class YnetParser(HtmlSoupParser): def parse_article(self, url, soup): ynet_id = re.findall(self.ARTICLE_ID_PATTERN, url)[0] title = soup.find('div', class_='art_header_title').text.strip().encode('iso-8859-1') - subtitle = soup.find('div', class_='art_header_sub_title').text.strip().encode('iso-8859-1') + try: + subtitle = soup.find('div', class_='art_header_sub_title').text.strip().encode('iso-8859-1') + except: + subtitle = '' author_bar = soup.find('span', class_='art_header_footer_author') author = author_bar.find('a').text.strip().encode('iso-8859-1') date = re.findall(r'\d\d.\d\d.\d\d', author_bar.text)[0] time = re.findall(r'\d\d:\d\d', author_bar.text)[0] article_date = self.TIMEZONE.localize(datetime.strptime(' '.join([date, time]), '%d.%m.%y %H:%M')) article_body = soup.find('div', class_='art_body').find_all('p') - article_text = '\n'.join([p.text.strip().encode('iso-8859-1') for p in article_body if p.text]) + try: + article_text = '\n'.join([p.text.strip().encode('iso-8859-1') for p in article_body if p.text]) + except: + article_text = '\n'.join([p.text.strip() for p in article_body if p.text]) with transaction.atomic(), reversion.create_revision(): try: |
