意外的标记“<”

Unexpected token '<'

我正在使用它在 div 标签之间添加 html 但它显示 Unexpected token '<'

browser.execute_script("arguments[0].innerHTML = " + f'{x["solution"]}', solution)

x["solution"] 是一个 json 文件,其中包含 html 等 <strong> bold </strong>

你忘了引用等号右边的部分。此代码正在生成:

arguments[0].innerHTML = <strong> bold </strong>

此外,您可以使用单一格式的字符串,如下所示:

browser.execute_script(f'arguments[0].innerHTML = "{x["solution"]}"', solution)

并会生成

arguments[0].innerHTML = "<strong> bold </strong>"