Esempio n. 1
0
def main():
    SEND_MSG = ("[自动回复]这里是机器人,稍后回复您的消息,"
                "抱歉.(望勿频繁调戏机器人...)")
    bot = Login()
    LOG.info('请扫描二维码.')
    print(bot.get_QRcode())
    os.remove('QRcode.png')
    Is_login = False
    while not Is_login:
        time.sleep(2)
        res = bot.is_login().split(',')[-2]
        LOG.info(res)
        Is_login = True if '登录成功' in res else False
    LOG.info('获取ptwebqq...')
    bot.get_ptwebqq()
    LOG.info('获取vfwebqq...')
    bot.get_vfwebqq()
    LOG.info('获取psessionid...')
    bot.get_psessionid()
    LOG.info('等待消息...')
    STOP = False
    is_open = True
    while not STOP:
        time.sleep(1)
        try:
            msg = bot.poll()
            msg_content, from_uin, msg_type = hand_msg(msg[0])
            LOG.info('{0} 发来一条消息: {1}'.format(from_uin, msg_content.encode('utf-8')))
            if (is_open is True) and ('STOP' not in msg_content):
                msg = "{0}[{1}]".format(SEND_MSG, random.randint(0, 10))
                send_status = bot.send_msg(msg, from_uin, msg_type)
                LOG.info('回复 {0}: {1}'.format(from_uin, send_status))
            elif 'STOP' in msg_content:
                LOG.info('CLOSE...')
                bot.send_msg('CLOSED', from_uin, msg_type)
                is_open = False
            elif 'START' in msg_content:
                LOG.info('STARTED')
                bot.send_msg('OPENED', from_uin, msg_type)
                is_open = True

        except KeyboardInterrupt:
            LOG.info('See You...')
            STOP = True
        except:
            LOG.error(sys.exc_info())
Esempio n. 2
0
def main():
    SEND_MSG = ("[自动回复]这里是机器人,稍后回复您的消息," "抱歉.(望勿频繁调戏机器人...)")
    bot = Login()
    LOG.info('请扫描二维码.')
    print(bot.get_QRcode())
    os.remove('QRcode.png')
    Is_login = False
    while not Is_login:
        time.sleep(2)
        res = bot.is_login().split(',')[-2]
        LOG.info(res)
        Is_login = True if '登录成功' in res else False
    LOG.info('获取ptwebqq...')
    bot.get_ptwebqq()
    LOG.info('获取vfwebqq...')
    bot.get_vfwebqq()
    LOG.info('获取psessionid...')
    bot.get_psessionid()
    LOG.info('等待消息...')
    STOP = False
    is_open = True
    while not STOP:
        time.sleep(1)
        try:
            msg = bot.poll()
            msg_content, from_uin, msg_type = hand_msg(msg[0])
            LOG.info('{0} 发来一条消息: {1}'.format(from_uin,
                                              msg_content.encode('utf-8')))
            if (is_open is True) and ('STOP' not in msg_content):
                msg = "{0}[{1}]".format(SEND_MSG, random.randint(0, 10))
                send_status = bot.send_msg(msg, from_uin, msg_type)
                LOG.info('回复 {0}: {1}'.format(from_uin, send_status))
            elif 'STOP' in msg_content:
                LOG.info('CLOSE...')
                bot.send_msg('CLOSED', from_uin, msg_type)
                is_open = False
            elif 'START' in msg_content:
                LOG.info('STARTED')
                bot.send_msg('OPENED', from_uin, msg_type)
                is_open = True

        except KeyboardInterrupt:
            LOG.info('See You...')
            STOP = True
        except:
            LOG.error(sys.exc_info())
Esempio n. 3
0
class Spider(object):
    def __init__(self, email, password):

        self.headers = {
            'Referer': 'https://github.com/',
            'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
            'Host': 'github.com'
        }
        self.email = email
        self.password = password
        self.foller_url = 'https://github.com/{name}?tab=followers'
        self.login = Login()
        self.session = self.login.login(email, password)
        self.set = set()

    def re_login(self):
        self.session = self.login.login(self.email, self.password)

    def is_login(self):
        return self.login.is_login()

    def get_follers(self, name):
        if name not in self.set:
            print("find user! " + name)
            self.set.add(name)
        else:
            return
        url = self.foller_url.format(name=name)
        response = self.session.get(url, headers=self.headers)
        selector = etree.HTML(response.text)
        list_ = selector.xpath('//a[@data-hovercard-type="user"]/@href')
        ll = []
        for li in list_:
            ll.append(li.replace("/", ''))
        list_ = list(set(ll))
        print("user name :" + name + " followers nums :" + str(len(list_)))
        for ll in list_:
            self.get_follers(ll)

    def run(self):
        self.get_follers("xiantang")