2010-04-06 30 views
0

很久以前,我写了一个小小的python脚本来自动登录我的办公室的无线网络。我的python自动登录脚本坏了

下面是代码:

#!/opt/local/bin/python 
from urllib2 import urlopen 
from ClientForm import ParseResponse 

try: 
if "Logged on as" in urlopen("https://MYWIRELESS.com/logon").read(): 
    print "Already logged on." 
else: 
    forms = ParseResponse(urlopen("https://MYWIRELESS.com/logon"), backwards_compat=False) 
    form = forms[0] 
    form["username"], form["password"] = "ME", "MYPASSWD" 
    urlopen(form.click()) 
    print "Logged on. (probably :-)"; 
except IOError, e: print "Couldn't connect to wireless login page:\n", e 

我最近改变了电脑,它停止工作。现在,我得到的错误:

File "login.txt", line 4, in <module> 
    from ClientForm import ParseResponse 
ImportError: No module named ClientForm 

这使得它看起来像我别有一番包(ClientForm)安装,所以我安装了它(sudo的港口安装PY-clientform),但我仍然得到同样的错误。有谁知道我做错了什么?

+0

它是在'site-packages '文件夹(id est,做哟你安装鸡蛋?) – 2010-04-06 21:19:10

回答

1

也检查你安装的包是在python路径:

>>> import sys 
>>> sys.path 
0

这个工作对类似的东西:

(能得到现场使用Wireshark来发送数据也是“用户”可能。如“用户名”与“密码”一样。再次wireshark会帮助这个。也可以看看登录页面的来源。祝你好运!!!)

from urllib import urlencode 
from urllib2 import Request, urlopen 

req = Request('www.site.com',urlencode({'user':'userhere', 'password':'passwordhere'})) 
open = urlopen(req)