使用 splinter 写入 html 正文

Use splinter to write to an html body

我从页面源代码中发现,论坛在未命名的 iframe 中写入了这样的内容:

<iframe style="height: 360px;">
    <html>
        <body>
        Forum text goes here.
        </body>
    </html>
</iframe>

我尝试使用 :

获取 ID
browser.execute_script("$('body').text('forum text')")

我认为它可以在 javascript 中用这样的东西完成,但我不确定如何找到有问题的元素,因为它没有标识符,而且很简单 browser.fill( 'body', text) 调用不起作用,因为它未标记为输入。

有问题的论坛托管在 proboards 上,如果有帮助的话。

编辑:对于任何对最终代码的样子感兴趣的人:

with browser.get_iframe(1) as iframe:
     iframe.execute_script("document.getElementsByTagName('body')[0].innerHTML = 'helloworld'")

你需要switch into the context of the iframe。由于它没有idname,只需通过索引切换到它。假设这是页面上的第一个 iframe

with browser.get_iframe(0) as iframe:
    # now we are inside the iframe