本文實(shí)例講述了Python爬取個(gè)人微信朋友信息操作。分享給大家供大家參考,具體如下:
	利用Python的itchat包爬取個(gè)人微信號(hào)的朋友信息,并將信息保存在本地文本中
思路要點(diǎn):
	1.利用itchat.login(),實(shí)現(xiàn)微信號(hào)的掃碼登錄
	2.通過itchat.get_friends()函數(shù)獲取朋友信息
代碼:
	本文代碼只獲取了幾個(gè)常用的信息,更多信息可從itchat.get_friends()中取
#獲取個(gè)人微信號(hào)中朋友信息#導(dǎo)入itchat包import itchat#獲取個(gè)人微信號(hào)好友信息if __name__=="__main__":  #登錄個(gè)人微信,掃碼登錄  itchat.login()  #爬取自己好友相關(guān)信息  friends=itchat.get_friends(update=False)[0:]  #設(shè)置需要爬取的信息字段  result=[('RemarkName','備注'),('NickName','微信昵稱'),('Sex','性別'),('City','城市'),('Province','省份'),('ContactFlag','聯(lián)系標(biāo)識(shí)'),('UserName','用戶名'),('SnsFlag','渠道標(biāo)識(shí)'),('Signature','個(gè)性簽名')]  for user in friends:    with open('myFriends.txt','a',encoding='utf8') as fh:      fh.write("-----------------------/n")    for r in result:      with open('myFriends.txt','a',encoding='utf8') as fh:        fh.write(r[1]+":"+str(user.get(r[0]))+"/n")  print("完成")希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選