`

新浪微博,自动加关注

阅读更多

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

 

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了。。

 

分享到:
评论
6 楼 key232323 2010-12-13  
chan.d 写道
写的这么飘逸,定睛只看最面前几行,

对,这不是java

于是放弃继续阅读。


哦,固守java的人呐。。。。难道要等java7 8出来后我们才开始用更简洁的语法么。。
5 楼 chan.d 2010-12-13  
写的这么飘逸,定睛只看最面前几行,

对,这不是java

于是放弃继续阅读。
4 楼 key232323 2010-12-10  
zgzdzh 写道
怎么一会儿Groovy,一会儿PHP?



因为不知道groovy的httpbuilder如何

curl_setopt( $ch, CURLOPT_USERPWD , "$uu:$pwd");
3 楼 ydz00ydz 2010-12-10  
第一段代码是java?
2 楼 zgzdzh 2010-12-10  
怎么一会儿Groovy,一会儿PHP?
1 楼 分离的北极熊 2010-12-10  
说实话,我真不想在这个时候看代码

相关推荐

    新浪微博批量删关注工具自动清理省心省力

    新浪微博批量删关注工具自动清理省心省力。新浪微博批量删除,微博自动清理,weibo删关注,微博批量删除工具软件

    python新浪微博爬虫,爬取微博和用户信息 (源码)

    这是新浪微博爬虫,采用python+selenium实现。 免费资源,希望对你有所帮助,虽然是傻瓜式爬虫,但是至少能运行。同时rar中包括源码及爬取的示例。 参考我的文章: ...[python爬虫] Selenium爬取新浪微博内容及用户...

    新浪微博推广大师 v10.5.rar

    V动力新浪微博推广大师是一款微博推广辅助软件、群发、推广、营销等,让用户更好的体验微博的魅力 V动力新浪微博推广大师功能介绍: 1.支持批量导入帐号,格式:帐号、密码,中间是|线;可以批量登陆,cookie缓存...

    网跃新浪微博内容采集直发工具 v2.1.zip

    网跃新浪微博内容采集直发工具是一款用于微博内容采集与批量发布的辅助工具,功能多样。 网跃新浪微博内容采集直发工具软件用途 1).微博内容采集(包括文本、图片、头像、微博数、关注数、粉丝数、是否加V、作者、...

    新浪微博转发软件

    要发新浪微博全能王是一款全自动代替手动进行新浪微博操作的智能化软件,新浪微博所有的转发,评论,赞,关注,私信,@,抽奖,都可以。需要的请在本站csdn下载哦。

    千鱼新浪微博机器人 v1.4.zip

    只要把您的新浪微博帐号放到软件里,并设置好:自动随机搜索关键词、操作间隔秒数、是否评论后转发到自己的微博、是否自动给我关注的人发评论,评论内容等参数,千鱼新浪微博机器人软件就可以自动按您的设置自动登录...

    新浪微博营销精灵 v1.6.3.10.zip

    2、同时对新浪微博做大量发送、对陌生人做@发送、对陌生人做评论、对粉丝做评论、留言、转发、收藏、加粉、取粉、传图、传头像; 3、支持发布多媒体博文; 4、支持管理微头像、并支持随机更新和发送; 5、可以...

Global site tag (gtag.js) - Google Analytics