我目前正在尝试使用Python从Foscam 8910W IP摄像机录制视频。
我首先咨询了这些主题:
How to parse mjpeg http stream from ip camera?
我完成了前几个命令
然后我意识到,由于我的相机的IP需要用户名和密码,我必须克服这个障碍。所以我安装了斜纹,并尝试使用斜纹命令登录:
How to log in to a website using installed twill?
我使用该线程登录斜纹外壳。然后我尝试了这个页面中的一些命令:
,例如
go("http://<camera's IP address>")
然后
show_forms()
此时我收到的回复是
<generator object __call__ at 0x106198780>
我注意到页面的源代码提到了cookie,所以我试过
show_cookies
我收到了类似的回复
<function show_cookies at 0x106026488>
我不知道从哪里去。我也试过模仿这个帖子:
How can I login to a website with Python?
我注意到我的IP cam登录页面的源代码提到了“login_user”和“login_pwd”变量。
from twill.commands import *
go('http://mysite.org')
fv("1", "email-email", "blabla.com")
fv("1", "password-clear", "testpass")
submit('0')
我以fv("1", "login_user", "<my_user_name>")
为例。我收到了一个错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/twill-0.9-py2.7.egg/twill/commands.py", line 433, in formvalue
raise TwillAssertionError("no matching forms!")
twill.errors.TwillAssertionError: no matching forms!
任何想法???
这是我要登录的页面的代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="style.css" type="text/css">
<title></title>
<style>
BODY {
MARGIN: 0px; BACKGROUND-COLOR: #969696; font: arial;
}
</style>
<script src="jquery-1.4.4.min.js"></script>
<script src="public.js"></script>
<script language = "javascript">
function OK()
{
top.user = document.getElementById("login_user").value;
top.pwd = document.getElementById("login_pwd").value;
top.$.getScript("check_user2.cgi?user="+encodeURIComponent(top.user)+'&pwd='+encodeURIComponent(top.pwd), function()
{
if(top.pri == 0) {
alert(top.str_ftp_error_user);
}
else
{
if ("" == top.pwd)
{
alert(top.str_pwd_note);
}
top.setcookie('login_user',top.user,720);
//top.setcookie('login_pwd',top.pwd,720);
location='login.htm';
}
})
}
function set_language(value)
{
if(value==0)
{
language='english';
}
else if(value==1)
{
language='Deutsch';
}
else if(value==2)
{
language='french';
}
else if(value==3)
{
language='Italian';
}
else if(value==4)
{
language='spanish';
}
else if(value==5)
{
language='Netherlands';
}
else if(value==6)
{
language='Polski';
}
else if(value==7)
{
language='Hungarian';
}
else if(value==8)
{
language='simple_chinese';
}
else if(value==9)
{
language='traditional_chinese';
}
else if(value==10)
{
language='Portugal';
}
else if(value==11)
{
language='Czech';
}
else if(value==12)
{
language='Turkish';
}
else if(value==13)
{
language='Russian';
}
else if(value==14)
{
language='Korean';
}
else if(value==15)
{
language='Indonesian';
}
else if(value==16)
{
language='Denmark';
}
else
{
language='english';
}
top.setcookie('language',language,720);
top.location.reload();//reload index.html
}
function get_language()
{
var lang_ret=0;
var tmp_lang=top.getcookie('language');
if(tmp_lang=='')
{
lang_ret=0;
}
else
{
if(tmp_lang=='english')
{
lang_ret=0;
}
else if(tmp_lang=='Deutsch')
{
lang_ret=1;
}
else if(tmp_lang=='french')
{
lang_ret=2;
}
else if(tmp_lang=='Italian')
{
lang_ret=3;
}
else if(tmp_lang=='spanish')
{
lang_ret=4;
}
else if(tmp_lang=='Netherlands')
{
lang_ret=5;
}
else if(tmp_lang=='Polski')
{
lang_ret=6;
}
else if(tmp_lang=='Hungarian')
{
lang_ret=7;
}
else if(tmp_lang=='simple_chinese')
{
lang_ret=8;
}
else if(tmp_lang=='traditional_chinese')
{
lang_ret=9;
}
else if(tmp_lang=='Portugal')
{
lang_ret=10;
}
else if(tmp_lang=='Czech')
{
lang_ret=11;
}
else if(tmp_lang=='Turkish')
{
lang_ret=12;
}
else if(tmp_lang=='Russian')
{
lang_ret=13;
}
else if(tmp_lang=='Korean')
{
lang_ret=14;
}
else if(tmp_lang=='Indonesian')
{
lang_ret=15;
}
else if(tmp_lang=='Denmark')
{
lang_ret=16;
}
}
return lang_ret;
}
function get_user()
{
var tmp_user = top.getcookie('login_user');
return tmp_user;
}
function get_pwd()
{
var tmp_pwd = top.getcookie('login_pwd');
return tmp_pwd;
}
function body_onload()
{
var lang_type=get_language();
document.getElementById("select_Language").value=lang_type;
//var pwd_type = get_pwd();
//document.getElementById("login_pwd").value = pwd_type;
var user_type = get_user();
document.getElementById("login_user").value = user_type;
}
$(function(){
$("#login_user").select().focus();
$("#login_user, #login_pwd, #login_botton, #select_Language").keydown(function(e){
if (e.keyCode == 13){
OK();
}
});
})
</script>
</head>
<body onLoad="body_onload()">
<div style="width:100%; height:50px;"></div>
<table border=0 cellpadding=0 cellspacing=0 width=400 height=250 align="center" style="font-family:Arial; background:url(images/loginbg1.gif) no-repeat">
<tr height = 60>
<td colspan="3">
<div > <font style="font: arial; "><strong><script>document.write(top.str_language_select);</script></strong></font>
<select name="select" id="select_Language" onChange="set_language(value)" >
<option value="0">English</option>
<option value="1">Deutsch</option>
<option value="2">Française</option>
<option value="4">España</option>
<option value="3">Italiano</option>
<option value="10">Portugal</option>
<option value="13">Pусский</option>
<option value="5">Nederland</option>
<option value="6">Polska</option>
<option value="7">Hungarian</option>
<option value="12">Türk</option>
<option value="11">Češka</option>
<option value="16">Dansk</option>
<option value="14">한국의</option>
<option value="15">Indonesia</option>
<option value="8">简体中文</option>
<option value="9">繁体中文</option>
</select>
</div>
</td>
<td></td>
<td> </td>
</tr>
<tr>
<td colspan="2"> </td>
<td height="10" valign=top align=right></td>
<td> </td>
</tr>
<tr align="center" height="40">
<td style=" float:right; line-height:40px;" colspan="2"><font style="font: arial;"><strong><script>document.write(top.str_user);</script></strong></font>
</td>
<td align="right"><div><input id="login_user" style="width: 146px; height: 23px;"/></div></td>
<td> </td>
</tr>
<tr align="center" height="40">
<td style="float:right; line-height:40px;" colspan="2"><font style="font: arial;"><strong><script>document.write(top.str_pwd);</script></strong></font>
</td>
<td align="right"><div><input id="login_pwd" type="password" style="width: 146px; height: 23px;"/></div></td>
<td> </td>
</tr>
<tr align="center" height = 70>
<td style="width:180px; float:right;" colspan="2"></td>
<td ><div id="login_botton" onClick="javascript:OK();" style="background:url('images/loginbutton1.png') no-repeat;width:100px;height:25px;cursor:pointer;line-height:25px; float:center;" ><font align="center" style="font: arial;"><strong><script>document.write(top.str_index_ok);</script></strong></font></div>
</td>
<td> </td>
</tr>
</table>
</body>
好的,我已经取得了一些进展。我意识到show forms()
命令没有产生任何输出的原因是因为我最初去过的网址。当我查看源代码时,我意识到浏览器中的地址已更改为/login_user.htm。所以使用go('http://000.00.000.00/login_user.htm')
然后'showforms()'
给了我正在寻找的输出:
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 select select select_L ... ['0'] of ['0', '1', '2', '4', '3', ' ...
2 None text login_user
3 None password login_pwd
现在fv('1','login_user', '<username>')
和fv('1','login_pwd', '<password>')
正在运行,但我在使用提交按钮时遇到了问题,但仍然存在。
对此有何看法?