首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

新浪微博,自动添关注

2012-12-23 
新浪微博,自动加关注写些程序,目的是为了新加入一些微群(互粉的),能够快速的积累自己的粉丝?Step1,模拟登

新浪微博,自动加关注

写些程序,目的是为了新加入一些微群(互粉的),能够快速的积累自己的粉丝

?

Step1,模拟登陆,找到目标页面,正则匹配出一个id列表

?

Step2,用Curl,根据新浪微博API借口,定时去加这些id

?

代码如下——

?

?

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-RC2' )import groovyx.net.http.*import static groovyx.net.http.ContentType.*import static groovyx.net.http.Method.*// sina blogdef get_weibo_ll_sina(String uu, String pwd, String uid, List url_ll, String dir, String app_key){if(!uu || !pwd)returntry {// 登陆def http = new HTTPBuilder()http.request( 'http://login.sina.com.cn/hd/signin.php', POST, TEXT ) {uri.query = [entry:'sso', act:'1', reg_entry:'space', reference:''] + [username:uu, password:pwd]response.success = { resp, reader ->//System.out << reader}response.failure = { resp ->println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"}}// 获取微博一些列表源码url_ll.eachWithIndex{it, ii ->http.request(it, GET, TEXT ) {response.success = { resp, reader ->File ff = new File(new File(dir), ii + '.html')new FileOutputStream(ff) << reader//(ff.text =~ /\/profile\/(\d+)/).each{gg ->//http.request('http://api.t.sina.com.cn/friendships/create.json', POST, JSON ) {//uri.query = [source:app_key, user_id:gg[1]]//headers.'User-Agent' = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.587.0 Safari/534.12'//headers.'Origin' = 'http://q.t.sina.com.cn'//headers.'Referer' = it////response.success = { resp2, reader2 ->//System.out << reader2//}////response.failure = { resp2 ->//println "Unexpected error: ${resp2.statusLine.statusCode} : ${resp2.statusLine.reasonPhrase}"//}//}//}}response.failure = { resp ->println "Unexpected error: ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"}}}}catch (ConnectException ex) {ex.printStackTrace()}catch (SocketTimeoutException ex) {ex.printStackTrace()}}List url_ll = [](1..10).each{url_ll << 'http://q.t.sina.com.cn/group.php?gid=164334&type=crt&page=' + it}get_weibo_ll_sina('username', 'password', 'your_id', url_ll, './down/', 'app-key')

?<?php

header('content-type:text/html; charset=utf-8');$uu = 'username';$pwd = 'password';$app_key = 'app_key';$to_uid_arr = array(111,222,);$post_url = 'http://api.t.sina.com.cn/friendships/create.json';// cookie文件路径$cookie_file = tempnam('F:/temp/cookie','cookie');// 关注微博foreach($to_uid_arr as $to_uid){$post_fields = array();$post_fields['source'] = $app_key;$post_fields['user_id'] = $to_uid;$ss = '';foreach($post_fields as $k => $one){$ss .= $k . '=' . $one . '&';}$ch = curl_init($post_url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $ss);curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt( $ch, CURLOPT_USERPWD , "$uu:$pwd");  echo(curl_exec($ch));curl_close($ch);sleep(5);}// 清理cookie文件unlink($cookie_file);?>
?

httpbuilder我没找到http认证的方法,遗憾,又结合Php的curl了。。

?

1 楼 分离的北极熊 2010-12-10   说实话,我真不想在这个时候看代码 2 楼 zgzdzh 2010-12-10   怎么一会儿Groovy,一会儿PHP? 3 楼 ydz00ydz 2010-12-10   第一段代码是java? 4 楼 key232323 2010-12-10   zgzdzh 写道怎么一会儿Groovy,一会儿PHP?


因为不知道groovy的httpbuilder如何

curl_setopt( $ch, CURLOPT_USERPWD , "$uu:$pwd"); 5 楼 chan.d 2010-12-13   写的这么飘逸,定睛只看最面前几行,

对,这不是java

于是放弃继续阅读。 6 楼 key232323 2010-12-13   chan.d 写道写的这么飘逸,定睛只看最面前几行,

对,这不是java

于是放弃继续阅读。

哦,固守java的人呐。。。。难道要等java7 8出来后我们才开始用更简洁的语法么。。

热点排行