<reponame>ldolin/shixi0
"""
created by ldolin
"""
from day13.common.requests_helper import make_session, create_referer_headers
import urllib3
urllib3.disable_warnings()


class WeiboSpyder:
    def __init__(self, username,password):
        # 建立session对象 alt+enter
        self.username = username
        self.password = password
        # 在程序中设置代理--测试
        # self.session = make_session(use_proxy=True)
        self.session = make_session()

    def visit_index(self):
        # 访问首页是为了得到cookie
        url = "https://passport.weibo.cn/signin/login"
        self.session.get(url)
        print('访问首页')

    def visit_sso_login(self):
        url = 'https://passport.weibo.cn/sso/login'
        headers = create_referer_headers("https://passport.weibo.cn/signin/login")
        data = {
            'username': self.username,
            'password': <PASSWORD>,
            'savestate': '1',
            'r': '',
            'ec': '0',
            'pagerefer': '',
            'entry': 'mweibo',
            'wentry': '',
            'loginfrom': '',
            'client_id': '',
            'code': '',
            'qq': '',
            'mainpageflag': '1',
            'hff': '',
            'hfp': ''
        }
        response = self.session.post(url, headers=headers,data=data)
        json_data = response.json()
        if json_data["retcode"] == 20000000:
            print('登录成功')
        else:
            print('登录失败：', json_data["msg"])

    def visit_friends(self):
        url = "https://m.weibo.cn/feed/friends?"
        headers = create_referer_headers("https://m.weibo.cn/")
        response = self.session.get(url, headers=headers)
        json_data = response.json()
        statuses = json_data['data']['statuses']
        for statuse in statuses:
            print('博主是：%s,内容是：%s' % (statuse["user"]["screen_name"], statuse["text"]))


if __name__ == '__main__':
    username ='<EMAIL>'
    password = '<PASSWORD>'
    weibo_spyder = WeiboSpyder(username,password)
    weibo_spyder.visit_index()
    weibo_spyder.visit_sso_login()
    weibo_spyder.visit_friends()

































    
"""
created by ldolin
"""
from day13.common.requests_helper import make_session, create_referer_headers
import urllib3
urllib3.disable_warnings()


class WeiboSpyder:
    def __init__(self, username,password):
        # 建立session对象 alt+enter
        self.username = username
        self.password = password
        # 在程序中设置代理--测试
        # self.session = make_session(use_proxy=True)
        self.session = make_session()

    def visit_index(self):
        # 访问首页是为了得到cookie
        url = "https://passport.weibo.cn/signin/login"
        self.session.get(url)
        print('访问首页')

    def visit_sso_login(self):
        url = 'https://passport.weibo.cn/sso/login'
        headers = create_referer_headers("https://passport.weibo.cn/signin/login")
        data = {
            'username': self.username,
            'password': <PASSWORD>,
            'savestate': '1',
            'r': '',
            'ec': '0',
            'pagerefer': '',
            'entry': 'mweibo',
            'wentry': '',
            'loginfrom': '',
            'client_id': '',
            'code': '',
            'qq': '',
            'mainpageflag': '1',
            'hff': '',
            'hfp': ''
        }
        response = self.session.post(url, headers=headers,data=data)
        json_data = response.json()
        if json_data["retcode"] == 20000000:
            print('登录成功')
        else:
            print('登录失败：', json_data["msg"])

    def visit_friends(self):
        url = "https://m.weibo.cn/feed/friends?"
        headers = create_referer_headers("https://m.weibo.cn/")
        response = self.session.get(url, headers=headers)
        json_data = response.json()
        statuses = json_data['data']['statuses']
        for statuse in statuses:
            print('博主是：%s,内容是：%s' % (statuse["user"]["screen_name"], statuse["text"]))


if __name__ == '__main__':
    username ='<EMAIL>'
    password = '<PASSWORD>'
    weibo_spyder = WeiboSpyder(username,password)
    weibo_spyder.visit_index()
    weibo_spyder.visit_sso_login()
    weibo_spyder.visit_friends()
created by ldolin # 建立session对象 alt+enter # 在程序中设置代理--测试 # self.session = make_session(use_proxy=True) # 访问首页是为了得到cookie