如何使用python将文件导入网页

问题描述 投票:0回答:1

我是Python初学者。我想知道如何将文件(.xls 或 .csv)导入到“http://www.naturfreunde-oberkochen.de/demos/simpledemo/index.php”等网页中。而不是手动选择文件并上传到网页。我试图通过脚本提供文件名,并使用 python 脚本将文件导入到网页中。 在此页面源代码中,有类似 <‌​/object> 的内容。如果我点击按钮,那么它就会从另一个 js 文件获取数据。 这里如何处理导入文件。

我能够获取网页的页面源,但不知道如何继续。

python
1个回答
0
投票

创建项目文件夹 在项目文件夹中创建模板文件夹 创建index.html和main.html到templates文件夹 在项目文件夹中创建一个app.py

像这样

project_folder/
│
├── templates/
│   └── main.html
│   └── index.html
│
└── app.py

main.html

<!-- templates/main.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Main HTML File</title>
</head>
<body>
    <h1>Hello from main.html!</h1>
    <p>This content is from the main HTML file.</p>
</body>
</html>

index.html

    <!-- templates/index.html -->
    <!DOCTYPE html>
    <html la

   ng="en">
   <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Import Example</title>
   </head>
   <body>
    <h1>Hello from index.html!</h1>
    <p>This content is from the index HTML file.</p>

    <!-- Import main.html -->
    {% include 'main.html' %}
</body>
</html>

应用程序.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run(debug=True)

首先安装flash

pip install flast

在终端中运行代码

并打开http://localhost:5000/

在index.html中可以看到main.html内容

© www.soinside.com 2019 - 2024. All rights reserved.