|
|
@@ -4,7 +4,7 @@ import datetime
|
|
|
import html
|
|
|
|
|
|
from functions import sanitizeUrl
|
|
|
-from newspaper import Article
|
|
|
+from newspaper import Article,Config
|
|
|
|
|
|
class News():
|
|
|
r=re.compile(r"hours? ago|yesterday|today|last week|month",flags=re.IGNORECASE)
|
|
|
@@ -34,20 +34,26 @@ class News():
|
|
|
self.CATEGORY=sourcecategory
|
|
|
self.MATCHING_KW=[]
|
|
|
|
|
|
+ config = Config()
|
|
|
+ config.language=lang
|
|
|
+ config.memoize_articles=False
|
|
|
+ config.keep_article_html=True
|
|
|
+ config.request_timeout=15
|
|
|
+ config.fetch_images=False
|
|
|
+ config.browser_user_agent="Mozilla/5.0 (X11; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0"
|
|
|
+
|
|
|
a=None
|
|
|
try:
|
|
|
- if html is None:
|
|
|
- a = Article(url, language=lang,keep_article_html=True,request_timeout=10)
|
|
|
- a.download()
|
|
|
- else:
|
|
|
- a= Article("",keep_article_html=True)
|
|
|
- a.set_html(html)
|
|
|
+ a = Article(url=url, config=config)
|
|
|
+ a.download(html=html)
|
|
|
|
|
|
a.parse()
|
|
|
a.nlp()
|
|
|
except Exception as e:
|
|
|
print("ERROR parsing/downloading/nlp article")
|
|
|
print(e)
|
|
|
+ print(url)
|
|
|
+ print(sourcename)
|
|
|
if html is not None:
|
|
|
print(len(html))
|
|
|
self.ERROR=True
|