(url: str)
| 85 | |
| 86 | @staticmethod |
| 87 | def crawl_file(url: str) -> str: |
| 88 | try: |
| 89 | response = requests.get(url) |
| 90 | filetype = os.path.splitext(url)[1] |
| 91 | if response.status_code == 200 and ( |
| 92 | any(ext in filetype for ext in ['.pdf', '.docx', '.csv', '.txt']) |
| 93 | ): |
| 94 | if response.content.strip(): |
| 95 | upload_file_name = url.split("/")[-1] |
| 96 | file_path = os.path.join("uploads", upload_file_name) |
| 97 | with open(file_path, "wb") as f: |
| 98 | f.write(response.content) |
| 99 | st.success(f"已保存文件: {upload_file_name}") |
| 100 | return response.content, filetype |
| 101 | else: |
| 102 | st.warning('Url cannot parse correctly.') |
| 103 | except: |
| 104 | st.warning('Url cannot parse correctly.') |
no test coverage detected