فهرست منبع

doc直接读取html部分优化

fangjiasheng 1 سال پیش
والد
کامیت
903d406fea
1فایلهای تغییر یافته به همراه5 افزوده شده و 3 حذف شده
  1. 5 3
      format_convert/convert_doc.py

+ 5 - 3
format_convert/convert_doc.py

@@ -1,5 +1,6 @@
 import inspect
 import os
+import re
 import sys
 from bs4 import BeautifulSoup
 sys.path.append(os.path.dirname(__file__) + "/../")
@@ -41,9 +42,10 @@ class DocConvert:
         try:
             with open(self.path, 'r') as f:
                 html_str = f.read()
-            soup = BeautifulSoup(html_str, 'lxml')
-            text = soup.text
-            is_html_doc = True
+            if re.search('<div|<html|<body|<head|<tr|<br|<table|<td', html_str):
+                soup = BeautifulSoup(html_str, 'lxml')
+                text = soup.text
+                is_html_doc = True
         except:
             pass