我目前使用的是ghost.py,他们有一个函数show(),当我调用它时,它会显示网站,但会立即关闭它。如何保持打开状态?
from ghost import Ghost
import PySide
ghost = Ghost()
with ghost.start() as session:
page, resources = session.open("https://www.instagram.com/accounts/login/?force_classic_login")
session.set_field_value("input[name=username]", "joe")
session.set_field_value("input[name=password]", "test")
session.show()
session.evaluate("alert('test')")发布于 2016-05-23 20:03:07
会话预览将保持打开状态,直到session退出-通过离开会话上下文,session.exit()将被隐式调用。要使其保持打开状态,您需要不退出会话上下文,或者不使用会话上下文。
前者可以这样实现:
from ghost import Ghost
import PySide
ghost = Ghost()
with ghost.start() as session:
page, resources = session.open("https://www.instagram.com/accounts/login/?force_classic_login")
session.set_field_value("input[name=username]", "joe")
session.set_field_value("input[name=password]", "test")
session.show()
session.evaluate("alert('test')")
# other python code后者可以这样实现:
from ghost import Ghost
import PySide
ghost = Ghost()
session = ghost.start()
page, resources = session.open("https://www.instagram.com/accounts/login/?force_classic_login")
session.set_field_value("input[name=username]", "joe")
session.set_field_value("input[name=password]", "test")
session.show()
session.evaluate("alert('test')")
# other python code但是,当python进程结束时,会话将不可避免地退出。同样值得注意的是,一些操作将在初始http请求完成后立即返回。如果您希望等待其他资源加载完毕,则可能需要调用session.wait_for_page_loaded()。我还发现,有些表单提交需要调用session.sleep()才能按预期运行。
https://stackoverflow.com/questions/36725722
复制相似问题