在 Ghost.py 脚本中使用 python 变量

Use python variables inside Ghost.py script

我试图用 Ghost.py 多次填写表格,我需要输入表格的值在列表中,程序如下所示:

inputData = ["input1", "input2", "andSoOn"]

ghost = Ghost()
with ghost.start():
    session = Session(ghost, download_images=False, display=True, user_agent=USER_AGENT)
    page,rs = session.open("http://somesite.org/fillme", timeout=120)
    assert page.http_status == 200

    # this is where i need the input data, to fill the values.
    session.evaluate("""
    document.querySelector('input[name="DataForm"]').value = "dataInput";
    """)

    # Do something and close
    session.webview.setHtml("")
    session.exit()

如何将值从 inputData 列表传递到脚本中的 querySelector 方法?我一直在尝试一切,但到目前为止没有运气。

运行 python 2.7,Ghost 0.2.3 和 PyQt4。提前致谢。

您尝试过使用 for 循环吗?

for input in inputData:
    session.evaluate('document.querySelector(\'input[name="DataForm"]\').value= "%s";' % input)