BeautifulSoup基本功能引起的内部错误

时间:2018-12-19 14:54:28

标签: python html web beautifulsoup

我想通过Python应用程序修改HTML内的倍数值。我发现我应该使用BeautifulSoup。我安装了它,现在我正试图把HTML代码当作汤料。

from flask import *
from bs4 import BeautifulSoup

import random
import socket
import json    
app = Flask(__name__, static_url_path='')

#BEAUTIFUL SOUP TEST------------------------------

with open("static/index.html") as fp:
    soup = BeautifulSoup(fp, "lxml")

#soup = BeautifulSoup("<html>data</html>")
#-------------------------------------------------
def send(data):
   #some code that aren't useful here

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

我没有关于错误的任何信息,只是当我要访问本地主机时出现内部错误

1 个答案:

答案 0 :(得分:0)

我发现应该将代码放入def中:

@app.route('/static/<path:path>')
def send_static(path):
    with open("static/index.html") as fp:
        html_doc = fp.read()

    soup = BeautifulSoup(html_doc, "html.parser")
    return send_from_directory('static', path)