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

在Ghost.py脚本中使用python变量,python,web-scraping,ghost.py,Python,Web Scraping,Ghost.py,我尝试用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://somes

我尝试用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方法?我什么都试过了,到目前为止运气都不好


运行Python2.7,使用Ghost 0.2.3和PyQt4。提前感谢。

您是否尝试使用for循环

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

成功了,我完全忘记了那件事,谢谢!