用python模拟登陆,发送飞信,现在还能用,header里面的user-agent不要发送
#-*- coding:UTF-8 -*-
import urllib,urllib2,cookielib,reclass Fetion:
__mobile = ''
__password = ''
__cookie = None
__cookieFile = './fetion_cookie.dat'
__serverUrl = "http://f.10086.cn"
__header = {
"Host":"f.10086.cn",
"Content-Type":"application/x-www-form-urlencoded",
# "User-Agent":"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5",
}
def __init__(self,mobile,passwd):
self.__mobile = mobile
self.__password = passwd
self.__cookie = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.__cookie))
urllib2.install_opener(opener)
def login(self):
postData = {
'm':self.__mobile,
'pass':self.__password,
'loginstatus':1
}
postUri = "/im/login/inputpasssubmit1.action"
return self.__postByCookie( postUri , postData )
def getFetionUid(self , mobile):
postData = {
'searchText':mobile,
}
postUri = "/im/index/searchOtherInfoList.action"
result = self.__postByCookie( postUri , postData )
uids = re.findall(r"name="internalid" value="(d*?)" />", str( result ))
return uids[0]
def __toFetionUid(self,fetionUid,msg):
postData = {
'msg':msg,
}
postUri = "/im/chat/sendMsg.action?touserid="+fetionUid
return self.__postByCookie( postUri , postData )
def send(self,mobile,msg):
if( msg =="" ):
raise Exception( "message is empty" )
#Exception.__init__()
return False
if( mobile == self.__mobile):
return self.toSelf( msg )
fetionUid = self.getFetionUid( mobile )
return self.__toFetionUid( fetionUid , msg )
def toSelf(self,msg):
postData = {
'msg':msg,
}
postUri = "/im/user/sendMsgToMyselfs.action"
return self.__postByCookie( postUri , postData )
def __postByCookie(self , path , postData ):
#发起请求
req = urllib2.Request(
url=self.__serverUrl + path,
data= urllib.urlencode(postData),#请求数据
headers = self.__header #请求头
)
result = urllib2.urlopen(req).read()
self.__cookie.save(self.__cookieFile)
return result
def logout(self):
postData = {}
postUri = "/im/index/logoutsubmit.action"
return self.__postByCookie( postUri , postData )
def __del__(self):
#self.logout()
pass
'''
fetionObj = Fetion("13681462000" , "mima")
fetionObj.login()
print fetionObj.send("13681462000","定时任务执行完毕1,gaga")
fetionObj.logout()
@珏 这个脚本现在已经不可用了,你需要自己分析f.10086.cn 的代码
邮箱的判断也有问题,现在QQ邮箱已经很常用了,但使用qq
邮箱却不能在你这留言、、、可能是正则表达式出问题了吧
你好,这个程序有语法错误,修正后扔不能用,我是来请教如何通过程序使用飞信给指定的人定期发送信息的,比如天气预报,我见你在micolog上上传过一个雅虎天气预报的插件,貌似它现在不能用了