https://passport.csdn.net/v1/api/app/scan/createAppScan
session = requests.session()
getlogin = session.post('https://passport.csdn.net/v1/api/app/scan/createAppScan', headers=headers).json()
token = getlogin['data']['token']
pngurl =getlogin['data']['url']
方法:就是将刷新CSDN登录页面,选择CSDN登录二维码,将二维码图片进行保存,然后用python对这二维码进行识别获取文字信息,或者用抖音APP登录功能直接进行扫码获取该二维码信息链接。获取信息之后发现该链接就是pngurl的参数
getlogin = session.post('https://passport.csdn.net/v1/api/app/scan/createAppScan', headers=headers).json()
token = getlogin['data']['token']
pngurl =getlogin['data']['url']
qr = qrcode.QRCode()
qr.add_data(pngurl)
img = qr.make_image()
# 缓存的好处就是不需要保存本地
a = BytesIO()
img.save(a, 'png')
png = a.getvalue()
a.close()
# 打开二维码进行扫码操作
t = showpng(png)
t.start()
https://passport.csdn.net/v1/api/app/scan/webRefreshToken
tokenurl = 'https://passport.csdn.net/v1/api/app/scan/webRefreshToken'
while 1:
qrcodedata = session.post(tokenurl, json={
"token": token}, headers=headers).json()
if '0' in str(qrcodedata['data']['code']):
print('二维码未失效,请扫码!')
elif '1' in str(qrcodedata['data']['code']):
print('已扫码,请确认!')
elif '2' in str(qrcodedata['data']['code']):
print('已确认,登录成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)#2秒访问1次
# -*- coding: utf-8 -*-
import pickle
import qrcode
import agent
from threading import Thread
import time
import requests
from io import BytesIO
from PIL import Image
import os
requests.packages.urllib3.disable_warnings()
headers = {
'User-Agent': agent.get_user_agents(), 'Referer': "https://passport.csdn.net/login?code=public"}
class showpng(Thread):
def __init__(self, data):
Thread.__init__(self)
self.data = data
def run(self):
img = Image.open(BytesIO(self.data))
img.show()
def islogin(session):
try:
session.cookies.load(ignore_discard=True)
except Exception:
pass
loginurl = session.get("https://msg.csdn.net/v1/im/query/historySession3", headers=headers).json()
if 'success' in str(loginurl['message']):
print('Cookies值有效,已登录!')
return session, True
else:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
#csdn软件扫码
def csdlogin():
# 写入
session = requests.session()
if not os.path.exists('csdncookies.cookie'):
with open('csdncookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
# 读取
session.cookies = pickle.load(open('csdncookies.cookie', 'rb'))
session, status = islogin(session)
if not status:
getlogin = session.post('https://passport.csdn.net/v1/api/app/scan/createAppScan', headers=headers).json()
token = getlogin['data']['token']
pngurl =getlogin['data']['url']
qr = qrcode.QRCode()
qr.add_data(pngurl)
img = qr.make_image()
# 缓存的好处就是不需要保存本地
a = BytesIO()
img.save(a, 'png')
png = a.getvalue()
a.close()
# 打开二维码进行扫码操作
t = showpng(png)
t.start()
tokenurl = 'https://passport.csdn.net/v1/api/app/scan/webRefreshToken'
while 1:
qrcodedata = session.post(tokenurl, json={
"token": token}, headers=headers).json()
if '0' in str(qrcodedata['data']['code']):
print('二维码未失效,请扫码!')
elif '1' in str(qrcodedata['data']['code']):
print('已扫码,请确认!')
elif '2' in str(qrcodedata['data']['code']):
print('已确认,登入成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)
with open('csdncookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
return session
if __name__ == '__main__':
csdlogin()
https://passport.csdn.net/v1/register/pc/officialAccount/createQrCode
getlogin = session.post('https://passport.csdn.net/v1/register/pc/officialAccount/createQrCode', headers=headers).json()
pngurl = session.get(getlogin['data']['qrCodeUrl'], headers=headers).content
t = showpng(pngurl)
t.start()
https://passport-api.csdn.net/v1/register/pc/officialAccount/checkLogin
tokenurl = 'https://passport-api.csdn.net/v1/register/pc/officialAccount/checkLogin'
while 1:
qrcodedata = session.post(tokenurl, headers=headers).json()
if '1070' in str(qrcodedata['code']):
print('二维码未失效,请扫码!')
elif '1015' in str(qrcodedata['code']):
print('二维码已失效!')
elif '0' in str(qrcodedata['code']):
print('已确认,登入成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)
# -*- coding: utf-8 -*-
import pickle
import qrcode
import agent
from threading import Thread
import time
import requests
from io import BytesIO
from PIL import Image
import os
requests.packages.urllib3.disable_warnings()
headers = {
'User-Agent': agent.get_user_agents(), 'Referer': "https://passport.csdn.net/login?code=public"}
class showpng(Thread):
def __init__(self, data):
Thread.__init__(self)
self.data = data
def run(self):
img = Image.open(BytesIO(self.data))
img.show()
def islogin(session):
try:
session.cookies.load(ignore_discard=True)
except Exception:
pass
loginurl = session.get("https://msg.csdn.net/v1/im/query/historySession3", headers=headers).json()
if 'success' in str(loginurl['message']):
print('Cookies值有效,已登录!')
return session, True
else:
print('Cookies值已经失效,请重新扫码登录!')
return session, False
#微信扫码
def csdlogin():
# 写入
session = requests.session()
if not os.path.exists('csdncookies.cookie'):
with open('csdncookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
# 读取
session.cookies = pickle.load(open('csdncookies.cookie', 'rb'))
session, status = islogin(session)
if not status:
getlogin = session.post('https://passport.csdn.net/v1/register/pc/officialAccount/createQrCode', headers=headers).json()
pngurl =session.get(getlogin['data']['qrCodeUrl'],headers=headers).content
t = showpng(pngurl)
t.start()
tokenurl = 'https://passport-api.csdn.net/v1/register/pc/officialAccount/checkLogin'
while 1:
qrcodedata =session.post(tokenurl, headers=headers).json()
if '1070' in str(qrcodedata['code']):
print('二维码未失效,请扫码!')
elif '1015' in str(qrcodedata['code']):
print('二维码已失效!')
elif '0' in str(qrcodedata['code']):
print('已确认,登入成功!')
break
else:
print('其他:', qrcodedata)
time.sleep(2)
with open('csdncookies.cookie', 'wb') as f:
pickle.dump(session.cookies, f)
return session
if __name__ == '__main__':
csdlogin()
https://bizapi.csdn.net/blog-console-api/v1/article/list?pageSize=20
x-ca-key: 2038……
x-ca-nonce: 27798095-6c0a-473……41
x-ca-signature: +zkhXW7/……JNsk=
access-control-max-age: 172……
x-ca-request-id: 96C4B4……B6703