写些程序,目的是为了新加入一些微群(互粉的),能够快速的积累自己的粉丝
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 blog def get_weibo_ll_sina(String uu, String pwd, String uid, List url_ll, String dir, String app_key){ if(!uu || !pwd) return try { // 登陆 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了。。