فهرست منبع

优化药品库显示

liuchengsen 1 ماه پیش
والد
کامیت
9b9e99fe66
1فایلهای تغییر یافته به همراه3 افزوده شده و 1 حذف شده
  1. 3 1
      data-pipeline/docx_ingest.py

+ 3 - 1
data-pipeline/docx_ingest.py

@@ -103,7 +103,9 @@ def _extract_images(doc, drug_name):
             if ext.lower() not in ('jpg', 'jpeg', 'png', 'gif', 'bmp'):
                 ext = 'png'
             # 用 rId hash 防止重复
-            fname = f"{drug_name}_{rId}.{ext}"
+            # 清理药名中的特殊字符,避免 URL 编码问题
+            safe_name = re.sub(r'[\s()() ]+', '_', drug_name).strip('_')
+            fname = f"{safe_name}_{rId}.{ext}"
             fpath = os.path.join(IMAGES_DIR, fname)
             if not os.path.exists(fpath):
                 with open(fpath, 'wb') as f: