版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
首先声明本模拟不稳定,有时会出现登陆不进去.模拟的原理请参考blog.csdn.net/mayongzhan的文章,相关的知识也请参考blog.csdn.net/mayongzhan.原来是因为csdn的metaweblog不能发布类别,所以采用模拟登陆然后发布.当然也发现了不少csdn秘密,比如隐藏的用于发送垃圾邮件 的field,还有很多csdn只隐藏没删掉的功能.有兴趣大家可以尝试一下,看看是否被封掉.回归xmlrpc了.这个东西发布出来给大家欣赏一下 by MyZ.
一些其他的hidden fields
发布到网页&ctl00%24cphContent%24EntryEditor1%24ckbPublished=on
允许在Blog首页显示&ctl00%24cphContent%24EntryEditor1%24chkIsAggregated=on
将正文内容复制到剪切板(只在IE下有效)&ctl00%24cphContent%24EntryEditor1%24chkCopytoClipboard=on
显示在我的主页&ctl00%24cphContent%24EntryEditor1%24chkDisplayHomePage=on
加站外好友邮件AddFriend.aspx
发邮件给站外好友ctl00$cphContent$EntryEditor1$ckbMailTo发短消息给站内好友ctl00$cphContent$EntryEditor1$ckbMessageTo推荐个编辑ctl00$cphContent$EntryEditor1$ckbRecommendTo
看到了吧.还有发邮件的功能,就是前一段时间出现的la圾邮件.本身如果是要推广的话...可以试试.
正文.上代码
--------------------------------------------------------------------------------------------
test.php
<?php/** * @name test.php * @date Sun Jul 20 12:31:20 CST 2008 * @copyright 马永占(MyZ) * @author 马永占(MyZ) * @link http://blog.csdn.net/mayongzhan/ */
//header("Content-type: text/html;charset=utf-8");header("Content-type: image/jpeg");session_start();
$url = 'http://hi.csdn.net/IndexLogIn.aspx';$url2 = 'http://hi.csdn.net/IndexLoginImage.aspx';
$post = 1;$returntransfer = 1;$port = 80;$header = 0;$nobody = 0;$followlocation = 1;
$cookie_jar = tempnam('./tmp','cookie.txt');$_SESSION['cookie_jar'] = $cookie_jar;
$ch = curl_init();$options = array(CURLOPT_URL => $url, CURLOPT_HEADER => $header, CURLOPT_NOBODY => $nobody, CURLOPT_PORT => $port, CURLOPT_RETURNTRANSFER => $returntransfer, CURLOPT_FOLLOWLOCATION => $followlocation, CURLOPT_COOKIEJAR => $cookie_jar );curl_setopt_array($ch, $options);$temp = curl_exec($ch);curl_close($ch);
//echo $temp;
preg_match_all('/id=/"__VIEWSTATE/" value=/"(//[0-9a-z]+)" //>/i',$temp,$tempArr);preg_match_all('/id=/"__EVENTVALIDATION/" value=/"(//[0-9a-z+]+)" //>/i',$temp,$tempArr2);
$_SESSION['__VIEWSTATE'] = $tempArr[1][0];$_SESSION['__EVENTVALIDATION'] = $tempArr2[1][0];
$ch2 = curl_init();$options2 = array(CURLOPT_URL => $url2, CURLOPT_HEADER => $header, CURLOPT_NOBODY => $nobody, CURLOPT_PORT => $port, CURLOPT_RETURNTRANSFER => $returntransfer, CURLOPT_FOLLOWLOCATION => $followlocation, CURLOPT_COOKIEFILE => $cookie_jar, CURLOPT_REFERER => $url );curl_setopt_array($ch2, $options2);$temp = curl_exec($ch2);curl_close($ch2);
echo $temp;
//$tem = file_get_contents($cookie_jar);print_r($tem);
//CURLOPT_URL是要得到内容的地址//CURLOPT_HEADER是要得到的头 //CURLOPT_NOBODY是要得到的内容 //CURLOPT_PORT是端口//CURLOPT_RETURNTRANSFER是要把输出的内容放到buffer中,可以被echo或者赋予某变量//CURLOPT_POST是标准的提交//CURLOPT_POSTFIELDS是提交的内容//CURLOPT_COOKIEJAR是要保存的cookie//CURLOPT_COOKIEFILE是从文件读取cookie并提交//CURLOPT_FOLLOWLOCATION启用时会将服务器服务器返回的“Location:”放在header中递归的返回给服务器//CURLOPT_MAXREDIRS限定递归返回的数量//CURLOPT_HTTPHEADER设置一个header中传输内容的数组//CURLOPT_REFERER设置header中"Referer:"部分的值//CURLOPT_USERAGENT在HTTP请求中包含一个”user-agent”头的字符串。//CURLOPT_ENCODING设定header中“Accept-Encoding: ”部分的内容,支持的编码格式为:"identity","deflate","gzip"。如果设置为空字符串,则表示支持所有的编码格式//CURLOPT_COOKIE设定HTTP请求中Set-Cookie:部分的内容?>
--------------------------------------------------------------------------------------------
test2.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="author" content="马永占(MyZ)" /><meta name="Copyright" content="马永占(MyZ)" /><meta http-equiv="Content-Language" content="utf-8" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><iframe src="test.php" scrolling="No" frameborder="0" width="400px" height="100px"></iframe><form action="test3.php" method="POST">VerifyCode:<input type="text" name="VerifyCode" /><br /><input type="submit" value="登陆" /></body></html>
--------------------------------------------------------------------------------------------
test3.php
<?php/** * @name test3.php * @date Sun Jul 20 12:31:30 CST 2008 * @copyright 马永占(MyZ) * @author 马永占(MyZ) * @link http://blog.csdn.net/mayongzhan/ */
header("Content-type: text/html;charset=utf-8");session_start();
$url = 'http://hi.csdn.net/IndexLogIn.aspx';
$post = 1;$returntransfer = 1;$port = 80;$header = 0;$nobody = 0;$followlocation = 1;
$request = '__VIEWSTATE='.urlencode($_SESSION['__VIEWSTATE']).'&__EVENTVALIDATION='.urlencode($_SESSION['__EVENTVALIDATION']).'&UserName=testman110&UserPwd=testman111111&VerifyCode='.$_POST['VerifyCode'].'&buttonLogin='.urlencode(' 登 录 ');
$cookie_jar = $_SESSION['cookie_jar'];
$ch = curl_init();
$options = array(CURLOPT_URL => $url, CURLOPT_HEADER => $header, CURLOPT_NOBODY => $nobody, CURLOPT_PORT => $port, CURLOPT_POST => $post, CURLOPT_POSTFIELDS => $request, CURLOPT_RETURNTRANSFER => $returntransfer, CURLOPT_FOLLOWLOCATION => $followlocation, CURLOPT_COOKIEJAR => $cookie_jar, CURLOPT_COOKIEFILE => $cookie_jar, CURLOPT_REFERER => $url );curl_setopt_array($ch, $options);$temp = curl_exec($ch);curl_close($ch);
echo $temp;?>
--------------------------------------------------------------------------------------------
the end
php不比任何的东西差.包括已经写出来csdn登陆的python c#.
转载于:https://www.cnblogs.com/xingyong/archive/2011/07/17/2108626.html
相关资源:详解python项目实战:模拟登陆