Python 爬虫——模拟登陆豆瓣

import requests

class Login(object):
    def __init__(self):
        self.headers = {'Referer': 'https://www.douban.com/login',
                         'Host': 'accounts.douban.com',
                         'User - Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64;rv: 60.0) Gecko / 20100101Firefox / 60.0'
                        }
        self.login_url = 'https://accounts.douban.com/login'
        self.post_url = 'https://accounts.douban.com/login'
        self.session = requests.session()

    def login(self, username, password):

        post_data = {
            'form_email': username,
            'form_password': password,
            'login': '登录',
            'redir': 'https://www.douban.com',
            'source': 'None'
        }
        response = self.session.post(self.post_url, data=post_data, headers=self.headers)
        print(response.text)

if __name__ =="__main__":
    login = Login()
    username = input('请输入用户名:')
    password = input('请输入密码:')
    login.login(username, password)

你可能感兴趣的:(python,大数据)