python登录微信获取好友群生成列表

该博客展示了如何使用Python实现微信登录,并获取好友和群聊列表。代码中使用了itchat库,结合PyQt5创建了用户界面,用于展示和操作。
摘要由CSDN通过智能技术生成

直接上代码

-- coding: utf-8 --

“””
Module implementing MainWindow.
“”“

from PyQt5.QtCore import QThread, pyqtSignal, Qt, pyqtSlot
from PyQt5.QtWidgets import *
from PyQt5 import QtGui

from Ui_cronSendMessage import Ui_MainWindow

import sys
import itchat
from itchat.content import *
import datetime
import time
import os
import requests
import json
import re
from urllib.request import urlretrieve
import traceback

current_path = os.path.dirname(os.path.abspath(file))

登陆微信

class LoginWechat(QThread):
# 自定义一个信号
finished_signal = pyqtSignal(object)

def __init__(self, parent=None, label=None, scroll_widget_layout=None, refresh_button=None, exit_button=None):
    super().__init__(parent)
    self.l = label
    self.scroll_widget_layout = scroll_widget_layout
    self.refresh_button = refresh_button
    self.exit_button = exit_button

# 在控制台中写入信息
def outputWritten(self, text=None):
    cursor = self.l.textCursor()
    cursor.movePosition(QtGui.QTextCursor.End)
    cursor.insertText(text)
    self.l.setTextCursor(cursor)
    self.l.ensureCursorVisible()

# 获取uuid
def open_qr(self):
    for get_count in range(1):
        self.outputWritten('获取uuid中……\n')
        uuid = itchat.get_QRuuid()
        while uuid is None:
            uuid = itchat.get_QRuuid()
            time.sleep(1)
        self.outputWritten('成功获取uuid\n')
        if itchat.get_QR(uuid, picDir=r'%s' % os.path.join(current_path, 'qrcode.jpg')):
            break
        elif get_count >= 1:
            self.outputWritten("获取二维码出错,请重启程序\n")
            sys.exit()
    return uuid

# 二维码登陆
def login_wechat(self):
    try:
        uuid = self.open_qr()
        self.outputWritten("请扫描二维码\n")
        waitForConfirm = False
        while 1:
            status = itchat.check_login(uuid)
            if status == '200':
                break
            elif status == '201':
                if waitForConfirm:
                    self.outputWritten('请进行确认\n')
                    waitForConfirm = True
            elif status == '408':
                self.outputWritten('重新加载二维码\n')
                time.sleep(3)
                uuid = self.open_qr()
                waitForConfirm = False
        userInfo = itchat.web_init()
        # print(userInfo)
        itchat.show_mobile_login()
        print('itchat.show_mobile_login() 执行完成!')
        # itchat.get_friends(True)
        itchat.get_friends()
        print('itchat.get_friends(update=True)[0:] 执行完成!')
        self.outputWritten('登陆成功!账号为:%s\n' % userInfo['User']['NickName'])
        itchat.start_receiving()
        print('itchat.start_receiving(
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值