让我知道如何使 html 显示一些响应值

Let me know how to make html to show some response values

我想编写一些代码来制作一个 html 文件来显示一些响应值。 所以我做了如下代码。但是我得到了 systaxError。 你能告诉我一些解决它的建议吗?

import requests
import os

URL = 'https://www.example'
response = requests.get(URL)

file=open('test.html','w',encoding='UTF-8')
file.write("<html><head><title>Test</title></head><body>"response.text"</body></html>")
file.closeenter code here

提前致谢。

您的 file.write 方法是错误的,请改用 f 字符串

import requests
import os

URL = 'https://www.example'
response = requests.get(URL)

file=open('test.html','w',encoding='UTF-8')
file.write(f"<html><head><title>Test</title></head><body>{response.text}</body></html>")