0

DynDNS 需要每月登录一次帐户以保持免费域处于活动状态。是否可以编写简单的脚本(在 Linux 中)来做到这一点?登录页面是这样的。

4

3 回答 3

1

如果您想用 python 编写它并将脚本托管在服务器上以便它无限地运行,您可以使用 Mechanize 库为您登录,并使用内置的时间每月执行一次。机械化:http ://stockrt.github.io/p/emulating-a-browser-in-python-with-mechanize/ 时间:http ://docs.python.org/2/library/time.html 免费托管:https://www.heroku.com/

于 2013-05-07T23:47:19.127 回答
1

你的意思是这样的:

import re
import mechanize

username = "username"
password = "password"
success_verification_text = "Log Out"

br = mechanize.Browser()
response = br.open("https://account.dyn.com/")


#select the login form
for form1 in br.forms():
    form = form1
    break;

br.select_form(nr=0)

form["username"] = username
form["password"] = password

response = br.submit()


if success_verification_text in response.read():
    print "SUCCESS"
else:
    print "FAILED"

https://gist.github.com/mandarl/6007396

于 2013-07-16T10:01:35.253 回答
0

如果您想成功登录,您需要选择登录表单。请求之间的表单 ID 会更改 (loginNNN),因此最好按名称搜索。

工作示例(需要mechanize):

import re
import mechanize

username = "xxx"
password = "xxxxxx"
success_verification_text = "Log Out"

br = mechanize.Browser()

response = br.open("https://account.dyn.com/")

# select the login form
cnt = 0
for frm in br.forms():
    if str(frm.attrs["id"]).find("login") != -1:
        form = frm
        break
    cnt += 1

br.select_form(nr=cnt)

form["username"] = username
form["password"] = password

response = br.submit()

if success_verification_text in response.read():
    print ("SUCCESS")
else:
    print ("FAILED")
于 2013-12-10T09:57:23.380 回答