python 2.7 using twill submit error

897 Views Asked by At

My python code to submit a value to Google:

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

When it is run it shows the following error:

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

There are 1 best solutions below

0
Ben Morris On

The key is formaction('1', 'www.google.com/search'), So in your case:

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

As for getting the code to actually search, I'm not sure.

You can do a google search by url with "http://www.google.com/?q=" + searchFor"