微博模拟登录以及查询某些的一页粉丝地址性别

import requests
import base64
import time
import rsa
import binascii
import urllib.parse
import re,urllib
from bs4 import BeautifulSoup
class weibo:
def __init__(self):
self.session = requests.session()
self.headers = {
'User-Agent':
}
self.proxies = {}
def get_secer_data(self,su):
prelogin_url = 'https://login.sina.com.cn/sso/prelogin.php?entry=weibo&callback=sinaSSOController.preloginCallBack&su=%s&rsakt=mod&client=ssologin.js(v1.4.19)&_=%s'%(su,str(int(time.time()*1000)))
pre_data_res = self.session.get(prelogin_url,headers = self.headers,proxies = self.proxies)
sever_data = eval(pre_data_res.content.decode("utf-8").replace("sinaSSOController.preloginCallBack",''))
return sever_data
def get_su(self,username):
username_quote = urllib.parse.quote_plus(username)
username_base64 = base64.b64encode(username_quote.encode("utf-8"))
return username_base64.decode("utf-8")
def get_password(self,password,servertime,nonce,pubkey):
rsaPublickey = int(pubkey,16)
key = rsa.PublicKey(rsaPublickey,65537)
message = str(servertime) + '\t' + str(nonce) + '\n' +str(password)
message = message.encode("utf-8")
passwor = rsa.encrypt(message,key)
passwor = binascii.b2a_hex(passwor)
return passwor
def login(self,su,sp,sever_data,nonce,rsakv,servertime):
data = {
'entry':'weibo',
'gateway':'1',
'from':'',
'savestate':'7',
'qrcode_flag': 'false',
'useticket': '1',
'pagerefer':'https://passport.weibo.com/visitor/visitor?entry=miniblog&a=enter&url=https%3A%2F%2Fweibo.com%2F%3Fsudaref%3Dwww.baidu.com%26display%3D0%26retcode%3D6102&domain=.weibo.com&sudaref=https%3A%2F%2Flogin.sina.com.cn%2Fsso%2Flogin.php%3Furl%3Dhttps%253A%252F%252Fweibo.com%252F%26_rand%3D1576318124.3653%26gateway%3D1%26service%3Dminiblog%26entry%3Dminiblog%26useticket%3D1%26returntype%3DMETA%26sudaref%3Dhttps%253A%252F%252Fwww.baidu.com%252Flink%253Furl%253D1Gxs_A1v8Lqn_zffSX5I3EMIqUQTJ3CoF4M7JWEeKni%2526wd%253D%2526eqid%253D936d55f70000e6ff000000045df4b4a9%26_client_version%3D0.6.28&ua=php-sso_sdk_client-0.6.28&_rand=1576318124.7105',
'vsnf': '1',
'su':su,
'service': 'miniblog',
'servertime':servertime,
'nonce':nonce,
'pwencode':'rsa2',
'rsakv':rsakv,
'sp':sp,
'sr': '1366 * 768',
'encoding': 'UTF-8',
'prelt': '35',
'url':'https://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
'returntype':'META'
}
url = 'https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.19)'
login_page = self.session.post(url, data=data)
login_loop = (login_page.content.decode("GBK"))
pa = r'location\.replace\([\'"](.*?)[\'"]\)'
loop_url = re.findall(pa,login_loop)[0]
lodin_index = self.session.get(loop_url)
url1 = re.findall(pa, lodin_index.text)[0]
url = 'https://weibo.com/ajaxlogin.php?'
html1 = self.session.get(url1)
html = self.session.get(url, headers=self.headers)
pa1 = r'(.*?)&url=.*?'
url2 = re.findall(pa1, url1)[0]
html2 = self.session.get(url2, headers=self.headers)
def get_uid(self,name):
url = 'https://s.weibo.com/user?q=%s'%name
html = self.session.get(url,headers = self.headers).text
soup = BeautifulSoup(html,'lxml')
p1 = soup.find(name='a', attrs={"target": "_blank"})
x = p1.attrs['href']
y = re.compile('\d+')
return y.findall(x)[0]
def get_xx(self,name,username,password):
su = self.get_su(username)
sever_data = self.get_secer_data(su)
servertime = sever_data["servertime"]
nonce = sever_data["nonce"]
rsakv = sever_data["rsakv"]
pubkey = sever_data["pubkey"]
sp = self.get_password(password,servertime,nonce,pubkey)
self.login(su,sp,sever_data,nonce,rsakv,servertime)
uid = self.get_uid(name)
url = 'https://weibo.com/u/'+uid
html = self.session.get(url,headers = self.headers).text
number = html.split("$CONFIG['page_id']='")[1].split("';")[0]
url1 = 'https://weibo.com/p/' + number + '/follow?relate=fans&page=2#Pl_Official_HisRelation__59'
html1 =self.session.get(url1).text
follow_unm = r'(\S+)<\\/a>'
follow_dz = r'地址<\\/em>(\S+\s?\S+?)<\\/span>\\r\\n\\t\\t\\t\\t\\t<\\/div>'
follow_xb = r'
'
addarss = re.findall(follow_dz, html1)
name = re.findall(follow_unm, html1)
xb = re.findall(follow_xb, html1)
list_add = []
list_name = []
list_xb = []
for i in addarss:
list_add.append(i)
for x in name:
list_name.append(x)
for p in xb:
list_xb.append(p)
for y in range(len(list_name)):
print("姓名", list_name[y])
print('地址', list_add[y])
print('性别', list_xb[y + 1])
'''
(),粉丝地址页的处理
(),储存功能
(),下一步做到自动关注、点赞、发微博

By-Huyer
2019-12-18

你可能感兴趣的:(微博模拟登录以及查询某些的一页粉丝地址性别)