【问题标题】:Internal errors caused with BeautifulSoup basic functionBeautifulSoup 基本功能导致的内部错误
【发布时间】:2018-12-19 14:54:27
【问题描述】:

我想通过我的 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')

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

【问题讨论】:

    标签: python html web beautifulsoup


    【解决方案1】:

    我想我应该将我的代码放入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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-11
      • 2018-01-11
      • 2020-12-28
      • 1970-01-01
      • 2013-07-07
      • 2021-10-07
      相关资源
      最近更新 更多