python 2.7使用斜纹提交错误

时间:2014-12-23 05:33:37

标签: python twill

我向Google提交值的python代码:

from twill.commands import *
go('www.google.com')
showforms()
formclear('1')
fv("1", "q", "python")
showforms()
submit('btnG')

运行时会显示以下错误:

***MissingSchema: Invalid URL u'/search': No schema supplied. Perhaps you meant http:///search?*** 

1 个答案:

答案 0 :(得分:1)

关键是formaction('1', 'www.google.com/search'),所以在你的情况下:

from twill.commands import *
go('www.google.com')
showforms()
formclear('1')
fv("1", "q", "python")
formaction('1', 'www.google.com/search')
showforms()
submit('btnG')

至于让代码实际搜索,我不确定。

您可以使用"http://www.google.com/?q=" + searchFor"

按网址进行Google搜索