scrapy 模拟post登录

以人人网为例:

# -*- coding: utf-8 -*-

import scrapy


class MyLoginSpider(scrapy.Spider):

    name = "loginSpider"
    allowed_domains = ["renren.com"]

    def start_requests(self):
        loginUrl = "http://www.renren.com/ajaxLogin/login"
        yield scrapy.FormRequest(url=loginUrl,
                                 formdata={"email": "****",
                                           "password": "****"},
                                 callback=self.parse)  # 发送post请求,提交表单数据

    def parse(self, response):
        print("*****************************************")
        print('*******', response.url)
        print(response.body.decode('utf-8'))

 

posted @ 2020-07-09 16:21  小心走火  阅读(27)  评论(0编辑  收藏