Browse Source

join html and link paths. unify config

David 10 năm trước cách đây
mục cha
commit
486e57b75c
1 tập tin đã thay đổi với 13 bổ sung7 xóa
  1. 13 7
      news.py

+ 13 - 7
news.py

@@ -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