Last active
December 18, 2020 05:55
-
-
Save kingwrcy/3181181 to your computer and use it in GitHub Desktop.
to get infomation from www.jiayuan.com ,a website where maybe u can find a girl friend there,LoL..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
########################################## | |
# to get infomation from www.jiayuan.com | |
# a website where maybe u can find a girl friend there,LoL.. | |
# need pyquery termcolor installed. | |
# sudo easy_install pyquery | |
# sudo easy_install termcolor | |
# by jerryWang 2012.7.26 | |
########################################## | |
import urllib ,urllib2 ,cookielib ,json,re | |
from pyquery import PyQuery as pq | |
from termcolor import colored | |
name = "[email protected]" | |
pwd = "******" | |
cj = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
urllib2.install_opener(opener) | |
personal_infomation = None | |
def login_to_jiayuan(name,password): | |
global personal_infomation | |
post_data = urllib.urlencode({'name': name, 'password': password, 'channel': '200','position':'201'}) | |
post_url = "http://www.jiayuan.com/login/dologin.php?new_header=1&channel=index" | |
req = urllib2.Request(post_url, post_data) | |
conn = urllib2.urlopen(req).read() | |
return_json = json.loads(conn) | |
personal_infomation = return_json | |
if return_json['err_type'] == 0: | |
return True | |
else: | |
return False | |
def show_personal_infomation(): | |
global personal_infomation | |
url = "http://msg.jiayuan.com/?from=menu" | |
return_strs = urllib2.urlopen(url).read() | |
d = pq(return_strs) | |
print colored("[*]nickname:%s" % (personal_infomation['nickname'],),'red') | |
print colored("[*]uid:%s" % (personal_infomation['uid'],),'red') | |
print colored("[*]sex:%s" % (personal_infomation['sex'],),'red') | |
print colored("[*]age:%s" % (personal_infomation['age'],),'red') | |
print colored("[*]unread_messages:%s" % (d("div.memberNumDiv.memberNumDivR td.numberInbox>div.numberR>a").text(),),'red') | |
print colored("[*]unused_stamps:%s" % (d("div.memberNumDiv2 td.numberInbox>div.numberR>a").text(),),'red') | |
def show_unread_messages(): | |
url = "http://msg.jiayuan.com/?from=menu" | |
return_strs = urllib2.urlopen(url).read() | |
d = pq(return_strs) | |
# unread_messages = d("li.weiduxinjian.bg1") #for unread messages | |
unread_messages = d("li.bg1") #for all 10 messages | |
if len(unread_messages) == 0: | |
print colored("[X]there is no unread messages now.!",'red') | |
for index in range(len(unread_messages)): | |
read_url = d(unread_messages[index]).find("div.huiyuan_jj.floatleft>a").attr('onclick') | |
m = re.findall(r'.*window.open\(\'(.*)\'\)',read_url) | |
print colored("%d\tfrom:%s" % (index+1,d(unread_messages[index]).find("td.nvta").text(),),'red') | |
print colored(" \ttitle: %s" % (d(unread_messages[index]).find("div.huiyuan_jj.floatleft>a").text(),),'red') | |
if m: | |
tmp_strs = urllib2.urlopen(m[0]).read() | |
b = pq(tmp_strs) | |
if(b("div.date").text() == None): | |
print "" | |
continue | |
print colored(" \ttime: %s" % (b("div.date").text(),),'red') | |
print colored(" \tcontent: %s" % (b(".text").text().replace("<!-- -voice -->",''),),'red') | |
print "" | |
def show_menu(): | |
while True: | |
print "->1.Show personal infomation." | |
print "->2.Show unread message." | |
print "->3.Show all message." | |
print "->4.Quit." | |
try: | |
choice = int(raw_input("pleae select a Number:")) | |
except Exception, e: | |
print "[X]please input a valid number between 1 to 4." | |
continue | |
if choice < 1 or choice >4: | |
print "[X]please input a valid number between 1 to 4." | |
if choice == 1: | |
show_personal_infomation() | |
elif choice == 2: | |
show_unread_messages() | |
elif choice == 4: | |
break | |
def main(): | |
if login_to_jiayuan(name,pwd): | |
print "[+]login success to jiayuan for %s .." % (name,) | |
else: | |
print "[+]login fail to jiayuan for %s ,please check your password or netword configuration!" % (name,) | |
show_menu() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment