Using Twill's submit function when website's submit button is localized(Python)

梦想与她 提交于 2019-12-21 21:58:53

问题


I am trying to pull information from a website, and doing so requires me to log into it. All goes well until I reach the submit button:

MissingSchema: Invalid URL u'/index.php?r=site/login': No schema supplied. 
Perhaps you meant http:///index.php?r=site/login?

From what I can understand, this is happening because the website redirects itself to a page on the server. Is there a way to make the button redirect to the full page instead of a local file on the server? Or am I even correct on why this error is occuring?

Thanks In Advance

The Gist of My Code:

from twill.commands import *
go('panel.picklehosting.com/index.php?r=site/login')
showforms()
formclear('1')
fv("1", "name", "usrname")
fv("1", "password", "mypass")
submit()

回答1:


I've been experiencing the same issue for a site I'm creating but I think I've solved it.

use the twill's formaction() function to set the action for the page you want. For example

    from twill.commands import *
    go('http://example.com/login')
    showforms() 
    fv("1", "nameField", "username")
    fv("1", "password", "password")
    formaction('form','http://example.com/login')
    submit("4")
    show()
    go('http://example.com/admin/')

or in your case

from twill.commands import *
go('panel.picklehosting.com/index.php?r=site/login')
showforms()
formclear('1')
fv("1", "name", "usrname")
fv("1", "password", "mypass")
formaction('form','panel.picklehosting.com/index.php?r=site/login')
submit()
go('panel.picklehosting.com/yourpage.php')


来源:https://stackoverflow.com/questions/28199938/using-twills-submit-function-when-websites-submit-button-is-localizedpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!