脉脉模拟登陆

说明

最近弄得最热的就是什么互联网寒冬,裁员等关键字,于是脉脉,领英的平台的热度就上去了,我就做了脉脉,领英的爬虫。

操作

脉脉模拟登陆难度不大,只是需要验证码处理

我用的云打码,数字的加减法

 1、通过抓包分析,登陆的地址为 https://acc.maimai.cn/login ,一个post请求。其中包含用户名,密码,验证码。其中验证码是有时候需要,有时候不需要。

data = {
            "m": self.username,
            "p": self.password,
            "v": ""
            "to": "",
            "pa": "+86"

        }

2、登陆成功之后就可以直接保存cookie,在爬虫的过程中就可以直接使用。

import requests
from yundamahttp import YDMHttp

class Login:
    def __init__(self):
        self.username = ""
        self.password = ""

        self.session = requests.session()

        self.headers = {
                'authority': "acc.maimai.cn",
                'cache-control': "max-age=0,no-cache",
                'origin': "https://acc.maimai.cn",
                'upgrade-insecure-requests': "1",
                'content-type': "application/x-www-form-urlencoded",
                'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
                'accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
                'referer': "https://acc.maimai.cn/login",
                'accept-encoding': "gzip, deflate, br",
                'accept-language': "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
        }

    def identify_code(self):
        ydm = YDMHttp()
        code = ydm.yundama()
        return code

    def login_normal(self):
        data = {
            "m": self.username,
            "p": self.password,
            "to": "",
            "pa": "+86"

        }
        log_url = "https://acc.maimai.cn/login"
        response = self.session.post(log_url, data=data, headers=self.headers)

        if "share_data" in response.text:
            print("没有验证码登陆成功")
            print(response.text)
        else:
            self.get_code()
            self.login_code()

    def get_code(self):
        codeurl = "https://acc.maimai.cn/code"
        r = self.session.get(codeurl)
        with open("code.jpg", "wb") as f:
            f.write(r.content)


    def login_code(self):
        url = "https://acc.maimai.cn/login"
        data = {
            "m": self.username,
            "p": self.password,
            "v": self.identify_code(),
            "to": "",
            "pa": "+86"

        }
        response = self.session.request("POST", url, data=data)
        if "share_data" in response.text:
            print("登陆成功")
            print(response.text)
        else:
            self.login_normal()

    def cookie(self):

        cookie = ""
        cookies = self.session.cookies

        for c in cookies:
            cookie = cookie + c.name + "=" + c.value + "; "
        return cookie

    def run(self):
        self.login_normal()


if __name__ == "__main__":
    l = Login()
    l.run()

    print(l.cookie())

 

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值