网址保密,只提供爬虫思路(实验学习所用,非商业用途)

1、发起首次请求,设置UA和cookie
2、翻页及formdata参数设置(注意这里的参数是以键值对的方式存在的)
3、首页数据的解析
4、详情页formdata的参数重构
5、档案页的数据解析

import scrapy
import json
from bosi.items import BosiItem
class BsSpider(scrapy.Spider):name = 'bs'# allowed_domains = ['xxxxxxxxx']start_urls = ['http://xxxxxxxxxxxxxxxxxxxxxx']#首次发起请求def start_requests(self):#翻页的urlurl = "http:xxxxxxxxxxxxxx"headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36","Cookie":"xxxxxxxxxxxxxxx; ASP.NET_SessionId=n1omhosmkcyjhyhba3meor0e; iflysse_client_sign=0f1d7195-8fca-4abd-b215-2dd2f15636e2; cacheHeader=%e9%bb%84%e5%a4%a9%e6%98%a5%3a1%3a%3a1; td_cookie=3746646333; SessionId=5bb2914e-d343-42b0-a49c-9a3779fde8a5"}for i in range(60):#formdata必须以键值对的形式封装,所以翻页int类型要转为str类型a=str(i*20)formdata={'sEcho':'1','iColumns':'6','sColumns':',,,,,','iDisplayStart':a,'iDisplayLength':'20','mDataProp_0':'UserObject','bSortable_0':'false','mDataProp_1':'Name','bSortable_1':'false','mDataProp_2':'Email','bSortable_2':'false','mDataProp_3':'IDCard','bSortable_3':'false','mDataProp_4':'GenderStr','bSortable_4':'false','mDataProp_5':'5','bSortable_5':'false','iSortCol_0':'0','sSortDir_0':'asc','iSortingCols':'1','Action':'0','SelectStr':'','ClassType':'0','ClassID':'-1',}#FormRequest相当于是手动指定post。yield scrapy.FormRequest(url,formdata=formdata,headers=headers, callback=self.parse)def parse(self, response):headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36","Cookie": "xxxxxxxxxxxxxxxx; ASP.NET_SessionId=n1omhosmkcyjhyhba3meor0e; iflysse_client_sign=0f1d7195-8fca-4abd-b215-2dd2f15636e2; cacheHeader=%e9%bb%84%e5%a4%a9%e6%98%a5%3a1%3a%3a1; td_cookie=3746646333; SessionId=5bb2914e-d343-42b0-a49c-9a3779fde8a5"}#页面数据是json格式,所以我们需要用json.loadsdict_data=json.loads(response.text)for item1 in  dict_data['aaData']:item=BosiItem()#学号item["UserObject"]=item1["UserObject"]#姓名item["UserName"]=item1["UserName"]#邮箱item["Email"]=item1["Email"]#身份证item["IDCard"]=item1["IDCard"]#性别item["GenderStr"]=item1["GenderStr"]#档案链接item["ObjectID"]=item1["ObjectID"]yield item#档案页链接url = "http://xxxxxxxxxxxxxxxxxxxx"formdata1 = {"Action": '2',#档案页链接实际是一串加密内容,通过ajax加载详情页数据"ID":item["ObjectID"]}                                                                                           #meta:请求传参yield scrapy.FormRequest(url, formdata=formdata1, headers=headers, callback=self.sun_parse, meta={"item": item})def sun_parse(self,response):dict_data2=json.loads(response.text)for item2 in dict_data2["Data"]["CourseList"]:item=response.meta["item"]#课程名称item["CourseName"]=item2["CourseName"]#时间item["DateStr"]=item2["DateStr"]#学习时长item["LearnTimeStr"]=item2["LearnTimeStr"]#进度item["ProgressStr"]=item2["ProgressStr"]#正确率item["CorrectRateStr"]=item2["CorrectRateStr"]#编译次数item["CompileNum"]=item2["CompileNum"]print(item)yield item

Scrapy 发起post请求相关推荐

  1. 16-爬虫之scrapy框架手动请求发送实现全站数据爬取03

    scrapy的手动请求发送实现全站数据爬取 yield scrapy.Reques(url,callback) 发起的get请求 callback指定解析函数用于解析数据 yield scrapy.F ...

  2. php 请求方式,PHP发起HTTP请求有哪几种方式?

    PHP发起HTTP请求方式有:1.通过[file_get_contents]发送get请求:2.通过[CURL]发送get请求:3.通过[fsocket]发送get请求. PHP发起HTTP请求方式有 ...

  3. dio网络框架封装_Flutter 使用dio来发起网络请求以及Cookie管理

    前言 Flutter官方建议您使用 dio 来发起网络请求,在学习过程中,也尝试过用dart io中的HttpClient发起的请求,这里主要讲一下dio的使用以及CookieJar.CookieMa ...

  4. Node.js模拟发起http请求从异步转同步的5种方法

    使用Node.js模拟发起http请求很常用的,但是由于Node模块(原生和第三方库)提供里面的方法都是异步,对于很多场景下应用很麻烦,不如同步来的方便.下面总结了几个常见的库API从异步转同步的几种 ...

  5. 木马——本质就是cs socket远程控制,反弹木马是作为c端向外发起网络请求

    摘自:http://kczxsp.hnu.edu.cn/upload/20150504165623705.pdf 里面对于木马的实验过程写得非常清楚,值得一看. 木马是隐藏在正常程序中的具有特殊功能的 ...

  6. Spring Boot 发起 HTTP 请求

    起步 新年目标Spring Cloud开始实施,打开慕课网. 刚学了一章,大体就是调用中国天气网的api,使用Spring Boot构建自己的天气预报系统,然后使用Spring Cloud,一步一步使 ...

  7. python使用scrapy_python使用scrapy发送post请求的坑

    标签: 使用 requests 发送 post 请求 先来看看使用requests来发送post请求是多少好用,发送请求 Requests 简便的 API 意味着所有 HTTP 请求类型都是显而易见的 ...

  8. openresty开发系列29--openresty中发起http请求

    openresty开发系列29--openresty中发起http请求 有些场景是需要nginx在进行请求转发 用户浏览器请求url访问到nginx服务器,但此请求业务需要再次请求其他业务: 如用户请 ...

  9. 发起http请求_关于HTTP请求发起和响应你了解多少

    在一个web程序开发中,一般都有前端和后端之分,前端负责向后端请求数据和展示页面,后端负责接收请求和做出响应发回给前端,他们之间的协作桥梁是API,而API其实就是一个URL,作为HTTP连接的一种具 ...

  10. 鸿蒙开发-使用fetch发起网络请求

    场景 鸿蒙基于JS搭建HelloWorld并修改国际化文件: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/118274050 在 ...

最新文章

  1. www.opensymphony.com - Class: java.net.PlainSocketImpl
  2. phpstudy添加redis扩展
  3. 阻止事件冒泡两种方式:event.stopPropagation();和return false;
  4. 在CentOs7上yum安装redis
  5. 浏览器测试基本跑分网站
  6. 纳达尔复出迎澳网开门红 直落三盘横扫本土选手
  7. 基于ARM-LINUX的温度传感器驱动-DS18B20
  8. 将k8容器中文件下载到本地
  9. k8s ingress配置自签名证书,并解决Kubernetes Ingress Controller Fake Certificate
  10. 关于一个博客系统的 整体架构与技术
  11. 无界鼠标 (Mouse without Borders) 一套键鼠控制多台电脑的工具(可跨电脑拷贝/拖放文件)
  12. python如何调用pyd_C#调用pyd
  13. Guava base -- Splitter
  14. 在lomboz eclipse 3.3中配置tomcat7/8 server运行时环境遇到的问题
  15. flexbison编写语法分析器
  16. torch.chunk与nn.Conv2d groups
  17. Linux网络相关命令:netstat,ss
  18. 多线程异常处理:挖掘页面空窗背后的原因
  19. 激活函数、损失函数和优化函数的比较
  20. Java-SSM-新冠疫苗接种登记系统

热门文章

  1. 7. Swift 基于Xmpp和openfire实现一个简单的登录注册
  2. 创建,删除和移动文件夹以及文件夹列表
  3. Eclipse中代码自动提示功能设置
  4. 14.卷1(套接字联网API)---高级IO函数
  5. 18.UNIX 环境高级编程--终端IO
  6. 63.magento 后台重置密码
  7. 6. ubuntu 下 mysql 数据库迁移
  8. 绝对定位元素、浮动元素会生成一个块级框
  9. 对 String 字符串的理解
  10. 洛谷 P2894 酒店 Hotel