소스 검색

优化药品库显示

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: