地址: https://m.weibo.cn 登陆接口: https://passport.weibo.cn/sso/login
不用抓包工具,直接用 chrome dev tools 就可以找到接口,没有验证码(试了几十次没有遇到过), Post 的账号密码数据也没有加密.... 是因为是测试版的缘故吗?
分享一下我模拟登陆的代码:
const superagent = require('superagent')
const weiboLogin = (username, password) => {
const loginApi = 'https://passport.weibo.cn/sso/login'
const formData = { username, password }
const headers = {
'Referer': 'https://passport.weibo.cn/signin/login',
'Content-Type': 'application/x-www-form-urlencoded'
}
return new Promise((resolve, reject) =>
superagent.post(loginApi)
.set(headers)
.send(formData)
.end((err, res) => {
if (err) reject('something went wrong.')
try {
const { rawHeaders, text } = res.res
const cookie = rawHeaders.filter(item => item.startsWith('SUB='))
.map(item => item.split(';')[0])
.join()
const uid = JSON.parse(text).data.uid
if (uid === undefined) reject('wrong password or username')
resolve({ cookie, uid }) // uid: user ID
} catch (err) {
reject('something went wrong.')
}
})
)
}
weiboLogin('username', 'password')
.then(res => console.log(res.cookie))
.catch(console.error)