python-selenium登录QQ空间
from selenium.webdriver import ActionChains
from selenium import webdriver
from time import sleep
import requests
import json
import re

'''
* 作者 LinOwl
'''
def SliderSpeed(distance):#加速度
    list_timeDistance = []
    t, sum_x, v0 = 0.7, 0, 1
    while (sum_x < distance):
        if (sum_x < distance * 0.7):
            a = 2
        else:
            a = -1
        v = v0
        s = v * t + 0.5 * a * pow(t, 2)
        sum_x += s
        list_timeDistance.append((distance-sum(list_timeDistance)) if sum_x > distance else s)
        v0 = v + a * t
    return list_timeDistance

def Get_gtk(p_skey):
    hash_ = 5381
    for key in p_skey:
        hash_ += (hash_ << 5) + ord(key)
    return str(hash_ & 0x7fffffff)


class action:
    def __init__(self):
        self.QQ_Number = '' #账号
        self.QQ_Password = '' #密码
        self.DictCookie = {} #cookie
        self.g_tk = ''
        self.Dic_QQfriend = {}
    def login(self):#登录QQ空间
        driver = webdriver.Chrome()
        # driver.maximize_window() #最大化

        driver.get('https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https%3A%2F%2Fqzs.qzone.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=https%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html&pt_no_auth=1')
        driver.find_element_by_xpath('//*[@id="switcher_plogin"]').click()
        driver.find_element_by_xpath('//*[@id="u"]').send_keys(self.QQ_Number)
        driver.find_element_by_xpath('//*[@id="p"]').send_keys(self.QQ_Password)
        driver.find_element_by_xpath('//*[@id="login_button"]').click()
        sleep(1)

        try:
            isoldurl = driver.current_url
            frame = driver.find_element_by_xpath('//*[@id="tcaptcha_iframe"]')  # 定位嵌套框架
            driver.switch_to.frame(frame)  # 进入嵌套框架
            while (isoldurl == driver.current_url and driver.current_url != 'https://user.qzone.qq.com/' + self.QQ_Number):
                driver.find_element_by_xpath('//*[@id="e_reload"]').click()  # 刷新滑块
                sleep(3)
                blud_bt = driver.find_element_by_xpath('//*[@id="tcaptcha_drag_thumb"]')
                ActionChains(driver).click_and_hold(on_element=blud_bt).perform()
                tracks = SliderSpeed(178)  # 滑块 拖动值在175左右
                for t_s in tracks:
                    ActionChains(driver).move_by_offset(xoffset=t_s, yoffset=0).perform()
                sleep(0.8)
                ActionChains(driver).release().perform()
        except:
            print('null')
        cookies = driver.get_cookies()
        for item in cookies:
            self.DictCookie[item['name']] = item['value']
        self.g_tk = Get_gtk(self.DictCookie['p_skey'])
        driver.close()

    def get_QQfriend(self):#遍历好友
        for offset in range(0,900001,50):
            html = requests.get('https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/right/get_entryuinlist.cgi?uin='+self.QQ_Number+'&fupdate=1&action=1&offset='+str(offset)+'&g_tk='+self.g_tk,cookies=self.DictCookie)
            json_str = json.loads(html.text.replace('_Callback(', '').replace(');', ''))
            friend_n = json_str['data']['uinlist'].__len__()
            for json_i in range(0, friend_n):
                self.Dic_QQfriend[json_str['data']['uinlist'][json_i]['label']] = json_str['data']['uinlist'][json_i]['data']
            if (friend_n < 50):
                break

    def add_QQfriend(self,QQnumber):#添加好友
        requests_data = {
            'sid':0,
            'ouin':QQnumber,
            'from_source':4,
            'uin':self.QQ_Number,
            'fupdate':1,
            'qzreferrer':'https%3A%2F%2Fuser.qzone.qq.com%2Fproxy%2Fdomain%2Fqzs.qq.com%2Fqzone%2Fv6%2Ffriend_manage%2Faddfriend%2Findex.html%23ouin%3D'+QQnumber+'%26sid%3D0%26from_source%3D4%26from%3D9',
            'flag':0,
            'groupId':0,
            'im':0,
            'from':9
        }
        respon_addData = requests.post('https://h5.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/tfriend/friend_addfriend.cgi?&g_tk='+self.g_tk,cookies=self.DictCookie,data=requests_data)
        print(re.findall('"message":"(.*?)",',respon_addData.text))


action = action()
action.login()
# action.get_QQfriend()
# print(action.Dic_QQfriend)
action.add_QQfriend('待加QQ')

ps:纯属娱乐,勿干坏事。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇