Skip to content

Commit

Permalink
people_news' test case
Browse files Browse the repository at this point in the history
  • Loading branch information
bustta committed Nov 4, 2014
1 parent fc07bf8 commit 9529d9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions NewsParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
# @Author: balicanta
# @Date: 2014-10-25 00:09:39
# @Last Modified by: bustta
# @Last Modified time: 2014-11-02 13:17:28
# @Last Modified by: kenny.tsai
# @Last Modified time: 2014-11-04 18:00:33

import sys

Expand All @@ -12,6 +12,7 @@
from strategies.LtnNewsParseStrategy import LtnNewsParseStrategy
from strategies.AnntwNewsParseStrategy import AnntwNewsParseStrategy
from strategies.CoolLoudParseStrategy import CoolLoudParseStrategy
from strategies.PeopleNewsParseStrategy import PeopleNewsParseStrategy
from strategies.AbstractNewsParseStrategy import AbstractNewsParseStrategy

from requests.utils import get_encodings_from_content
Expand All @@ -34,7 +35,6 @@ def __init__(self, URL):

def _fetchContent(self):
r = requests.get(self.url)

# Dynamic Get Encode From Content, get First as default
self.encoding = get_encodings_from_content(r.content)[0]

Expand All @@ -48,7 +48,7 @@ def _fetchContent(self):
def _validataion(self):
if(self.content_soup_object is None):
content = self._fetchContent()
self.content_soup_object = BeautifulSoup(content)#, 'html5lib')
self.content_soup_object = BeautifulSoup(content)

if(self.parse_strategy is None):
print "Non Support URL", self.url
Expand Down
8 changes: 5 additions & 3 deletions tests/NewsParser_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
# @Author: balicanta
# @Date: 2014-10-25 09:57:26
# @Last Modified by: bustta
# @Last Modified time: 2014-11-02 13:23:11
# @Last Modified by: kenny.tsai
# @Last Modified time: 2014-11-04 17:21:40


from NewsParser import NewsParser
Expand All @@ -19,7 +19,9 @@
{"url": "http://www.anntw.com/articles/20141031-GrlZ",
"title": "立法治樹典範", "author":"杜胤廣", "content": "因看見偏鄉農民生活困"},
{"url": "http://www.coolloud.org.tw/node/80590",
"title": "澳洲打工遭台商剝削", "author":"王顥中", "content": "青年勞動九五聯盟29日上午召開記者會"}
"title": "澳洲打工遭台商剝削", "author":"王顥中", "content": "青年勞動九五聯盟29日上午召開記者會"},
{"url": "http://www.peoplenews.tw/news/80a3de53-1c06-4d30-a330-b76e335132f7",
"title": "協助弱勢募款", "author":"朱蒲青", "content": "沒有什麼假想敵啦"}
]


Expand Down

0 comments on commit 9529d9d

Please sign in to comment.