Exemplo n.º 1
0
    def onLoadFinished(self):

        global USERVID
        global headers
        global headers_p

        # 获取cookies
        cookies = [
            '{}={};'.format(key, value)
            for key, value in self.DomainCookies.items()
        ]
        cookies = ' '.join(cookies)
        # 添加Cookie到header
        headers.update(Cookie=cookies)
        headers_p.update(Cookie=cookies)
        # 判断是否成功登录微信读书
        if login_success(headers):
            #判断temp文件夹是否存在,不存在则创建
            temp_dir = os.getcwd() + "\\temp"
            if not os.path.exists(temp_dir):
                os.makedirs(temp_dir)
            #登录成功后写入cookie
            with open(cookie_file, 'w', encoding='utf-8') as f:
                f.write(cookies)
            print('登录微信读书成功!')
            # 获取用户user_vid
            if 'wr_vid' in self.DomainCookies.keys():
                USERVID = self.DomainCookies['wr_vid']
                print('用户id:{}'.format(USERVID))
                # 关闭整个qt窗口
                self.close()

        else:
            self.profile.cookieStore().deleteAllCookies()
            print('请扫描二维码登录微信读书...')
Exemplo n.º 2
0

if __name__ == '__main__':
    #cookie文件存在时尝试从文件中读取cookie登录
    if os.path.exists(cookie_file) and os.path.isfile(cookie_file):
        #读取
        with open(cookie_file, 'r', encoding='utf-8') as f:
            cookie_in_file = f.readlines()
        #尝试登陆
        headers_from_file = headers
        headers_from_file.update(Cookie=cookie_in_file[0])
        if login_success(headers_from_file):
            print('登录微信读书成功!')
            #登录成后更新headers
            headers = headers_from_file
            headers_p.update(Cookie=cookie_in_file[0])
            #获取用户user_vid
            for item in cookie_in_file[0].split(';'):
                if item.strip()[:6] == 'wr_vid':
                    USERVID = int(item.strip()[7:])
        else:
            app = QApplication(sys.argv)  # 创建应用
            window = MainWindow()  # 创建主窗口
            window.show()  # 显示窗口
            app.exec_()  # 运行应用,并监听事件
    #文件不存在时再启用登录界面
    else:
        app = QApplication(sys.argv)  # 创建应用
        window = MainWindow()  # 创建主窗口
        window.show()  # 显示窗口
        app.exec_()  # 运行应用,并监听事件