from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel
from PyQt5.QtGui import QImage, QPixmap
class UI(QMainWindow):
def __init__(self, parent=None):
super(UI, self).__init__(parent)
self.setWindowTitle('登陆')
self.resize(150, 150)
self.setup_ui()
def setup_ui(self):
Label = QLabel(self)
Label.setGeometry(0, 0, 150, 150)
Label.setStyleSheet("border: 2px solid red")
def initUI(self, img):
image = QImage.fromData(img)
pixmap = QPixmap.fromImage(image)
Label = self.findChild(QLabel)
Label.setPixmap(pixmap)
Label.setScaledContents(True)
import requests
import json
import base64
import time
import random
from UI_界面 import UI as ui
from PyQt5.QtWidgets import QApplication
import sys
from threading import Thread
class Quick_hand():
def __init__(self, ginseng_id=''):
millis = int(round(time.time() * 1000))
print(millis)
Hm = ''
for i in range(1, random.randint(1, 4)):
Hm += str(millis - random.randint(1000, 99999)) + ','
Hm = Hm[:-1]
cookies = "did=web_92ff52e1f2ba9f2dd724cfc087c935e2; didv=" + str(
millis) + "; Hm_lvt_86a27b7db2c5c0ae37fee4a8a35033ee=" + Hm + "; clientid=3; client_key=65890b29; needLoginToWatchHD=1; Hm_lpvt_86a27b7db2c5c0ae37fee4a8a35033ee=1565607031"
self.headers = self.__login_sub_head(ginseng_id, cookies=cookies)
print('初始化Cookie', self.headers['Cookie'])
self.app = QApplication(sys.argv)
self.My_UI = ui()
sys.exit(self.app.exec_())
def login(self, ginseng_id=''):
url = 'https://id.kuaishou.com/rest/c/infra/ks/qr/start/'
data = 'sid=kuaishou.live.web'
return_data = requests.post(url, headers=self.headers, data=data)
return_data.encoding = 'UTF-8-SIG'
json_image = json.loads(return_data.text)['imageData']
temp = base64.b64decode(json_image)
local_post_data = {'qrLoginToken': json.loads(return_data.text)['qrLoginToken'],
'qrLoginSignature': json.loads(return_data.text)['qrLoginSignature'],
}
self.My_UI.initUI(temp)
self.My_UI.show()
self.thread01 = Thread(target=self.login_tem, args=(local_post_data,))
self. thread01.start()
sys.exit(self.app.exec_())
def login_tem(self, local_post_data):
url = 'https://id.kuaishou.com/rest/c/infra/ks/qr/scanResult'
return_data = requests.post(url, headers=self.headers, data=local_post_data)
print("请求返回值:", return_data.text)
if json.loads(return_data.text)['result'] == 1:
user = {
'eid': json.loads(return_data.text)['user']['eid'],
'user_sex': json.loads(return_data.text)['user']['user_sex'],
'user_id': json.loads(return_data.text)['user']['user_id'],
'user_name': json.loads(return_data.text)['user']['user_name'],
}
local_post_data['sid'] = 'kuaishou.live.web'
self.My_UI.close()
self.login_suer(local_post_data)
elif json.loads(return_data.text)['result'] == 707:
user = return_data.text
self.login()
print('没有打印就退出了')
else:
user = {'类型': '错误'}
print("user", user)
def login_suer(self, Submit_data=''):
url = 'https://id.kuaishou.com/rest/c/infra/ks/qr/acceptResult'
return_data = requests.post(url, headers=self.headers, data=Submit_data)
print(return_data.text)
def sub_data(self, ginseng_id, ginseng_pcursor=''):
local_post_data = {"operationName": "publicFeedsQuery",
"variables": {"principalId": ginseng_id, "pcursor": ginseng_pcursor, "count": 24},
"query": "query publicFeedsQuery($principalId: String, $pcursor: String, $count: Int) {\n publicFeeds(principalId: $principalId, pcursor: $pcursor, count: $count) {\n pcursor\n live {\n user {\n id\n kwaiId\n eid\n profile\n name\n living\n __typename\n }\n watchingCount\n src\n title\n gameId\n gameName\n categoryId\n liveStreamId\n playUrls {\n quality\n url\n __typename\n }\n followed\n type\n living\n redPack\n liveGuess\n anchorPointed\n latestViewed\n expTag\n __typename\n }\n list {\n photoId\n caption\n thumbnailUrl\n poster\n viewCount\n likeCount\n commentCount\n timestamp\n workType\n type\n useVideoPlayer\n imgUrls\n imgSizes\n magicFace\n musicName\n location\n liked\n onlyFollowerCanComment\n relativeHeight\n width\n height\n user {\n id\n eid\n name\n profile\n __typename\n }\n expTag\n __typename\n }\n __typename\n }\n}\n"}
local_post_data = str(local_post_data).replace("'", '"').replace(', ', ',').replace(' ', '', 5)
return local_post_data
def sub_head(self, ginseng_id):
local_headers = {
"Host": "live.kuaishou.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0",
"Accept": "*/*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://live.kuaishou.com/profile/" + ginseng_id,
"content-type": "application/json",
"Cookie": "clientid=3; did=web_79aee2e860f5438d897ddb18f84c1365; client_key=65890b29; didv=1565316325000; kuaishou.live.bfb1s=3e261140b0cf7444a0ba411c6f227d88",
}
return local_headers
def __login_sub_head(self, ginseng_id='', cookies=''):
local_headers = {
"Host": "id.kuaishou.com",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://live.kuaishou.com/profile/" + ginseng_id,
"content-type": "application/x-www-form-urlencoded",
"Content - Length": "21",
"Origin": "https: // live.kuaishou.com",
"Connection": "keep - alive",
"Cookie": cookies,
}
return local_headers
from class_快手 import Quick_hand
from UI_界面 import UI as ui
import sys
from PyQt5.QtWidgets import QApplication
from threading import Thread
if __name__ == '__main__':
ks = Quick_hand()
ks.login('www0-0www')