我的Python自动登录脚本坏了

2024-09-29 23:17:02 发布

您现在位置: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

我最近换了台电脑,结果电脑坏了。现在,我得到了一个错误:

^{pr2}$

这使我看起来好像没有安装某个包(ClientForm),所以我安装了它(sudo port install py ClientForm),但仍然收到相同的错误。有人知道我做错了什么吗?在


Tags: fromhttpsimportformcomonformsurlopen
2条回答

还要检查您安装的包是否在python路径中:

>>> import sys
>>> sys.path

这也适用于类似的情况:

(能够让网站使用wireshark发送数据。“user”也可能是其他东西,例如“username”与“password”相同。再一次,wireshark会帮忙的。也可以查看登录页面的源代码。祝你好运!!!)在

from urllib import urlencode
from urllib2 import Request, urlopen

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

相关问题 更多 >

    热门问题