声明:本文仅供学习参考

这个功能终于实现了,如果请求太快,很容易被系统发现(输入验证码)所以没用多线程

对于cookie的获取采取手动方式,也可以尝试从浏览器获取cookie,cookie需要转化为字典形式

 # coding   :utf-8
 # @Time    : 2017/8/7 8:00
 # @Author  : Yong-life
 # @File    : translateCookies.py

 def translatestr(cookie):
     cookie = cookie.replace('Cookie:','')
     cookie = cookie.replace(' ','')
     cookies = cookie.split(';')
     for i in range(len(cookies)):
         cookies[i] = cookies[i].replace('=', ':', 1)
     cookies_dict = {}
     for header in cookies:
         L = header.split(':' ,1)
         cookies_dict[L[0]] = L[1]
     return cookies_dict

手动模拟了几遍,发现关键的几部,就可以完成了

 # coding   :utf-8
 # @Time    : 2017/8/7 9:19
 # @Author  : Yong-life
 # @File    : CrawlingNetStudyRoom.py

 import re
 import time
 import requests
 from translateCookies import translatestr
 def gethtml(url):
     cookie = '__dxca=75091f84-4096-4d77-ba79-47356cc19b1e; 2334userinfo=bd47f4dce1b38171d15866435d79f7a9d807a544f7930b6abeaaa6286f1f1754e7876672f860a859c0433867ead52763adde0d57e85b541e; 2334UID=27561080; 2334enc=2DC5074C7374D67F2ACD4C1F5A7E7F56; _uid=27561080; uf=0d7d2f765ae428714a3fffffed66c4445f985d480e6f2f069b0594e13f4b452f9f4fcd6f19e32a2edcaf7a1eebd6007c0d8a4c92b12beb4be5b05dc70bcb18cfc05a9b956030332946da21146a924e23; _d=1502066525521; UID=27561080; vc=2DC5074C7374D67F2ACD4C1F5A7E7F56; vc2=AD5E945ED353A9AE790FA793E860A279; DSSTASH_LOG=C_38-UN_968-US_27561080-T_1502066525521; k8s=ba998ae2451b05102dd62f59c4aae09e27424974; route=7aaebcbdcf7cf94856c7fb5f82d77b4b; fanyamoocs=5CED1B5320BFFBA211401F839C536D9E; fid=2334; isfyportal=1; JSESSIONID=42822D4D414525EFAF03F092E432FCEA'
     cookie = translatestr(cookie)
     header = {
         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
         'Content-Type': 'text/html;charset=UTF-8'#
     }
     response = requests.get(url, headers=header, cookies=cookie)
     return response.text
 def crawlingClassid(html):
     classidList = []
     pattern_classid = 'class="Mcon1img httpsClass" >[\s]*<a[\s]*href=\'(.*?)\'  target="_blank"   >'
     classidList.extend(re.findall(pattern_classid, html))
     fileList = []
     pattern_file = r'class="Mcon1img">[\s]*<input type="hidden" value="(.*?)" />'
     fileList.extend(re.findall(pattern_file, html))
     for file_id in fileList:
         file_url = 'http://mooc1.xynu.edu.cn/visit/courses/study?isAjax=true&fileId=' + file_id
         classidList.extend(crawlingClassid(gethtml(file_url)))
     return classidList
 def sendMsg(courseId, clazzid, count):
     url = 'http://mooc1.xynu.edu.cn/bbscircle/grouptopic/publish'
     cookie = '__dxca=75091f84-4096-4d77-ba79-47356cc19b1e; 2334userinfo=bd47f4dce1b38171d15866435d79f7a9d807a544f7930b6abeaaa6286f1f1754e7876672f860a859c0433867ead52763adde0d57e85b541e; 2334UID=27561080; 2334enc=2DC5074C7374D67F2ACD4C1F5A7E7F56; _uid=27561080; uf=0d7d2f765ae428714a3fffffed66c4445f985d480e6f2f069b0594e13f4b452f9f4fcd6f19e32a2edcaf7a1eebd6007c0d8a4c92b12beb4be5b05dc70bcb18cfc05a9b956030332946da21146a924e23; _d=1502066525521; UID=27561080; vc=2DC5074C7374D67F2ACD4C1F5A7E7F56; vc2=AD5E945ED353A9AE790FA793E860A279; DSSTASH_LOG=C_38-UN_968-US_27561080-T_1502066525521; k8s=ba998ae2451b05102dd62f59c4aae09e27424974; route=7aaebcbdcf7cf94856c7fb5f82d77b4b; fanyamoocs=5CED1B5320BFFBA211401F839C536D9E; fid=2334; isfyportal=1; JSESSIONID=42822D4D414525EFAF03F092E432FCEA'

     cookie = translatestr(cookie)
     header = {
         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
         'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'  #
     }
     for i in range(1, count):
         data = ('courseId='+ courseId +'&clazzid='+ clazzid +'&title='+ str(i) +'&content=&type=4&files=').encode('utf-8')
         print('send: ' + courseId +' '+ str(i))
         response = requests.post(url, data, cookies=cookie, headers=header)
         time.sleep(3)
 def managerCrawling():
     url = 'http://mooc1.xynu.edu.cn/visit/courses?template=1&s=7c6b45e1ac1448adf0ff862c75c8ab3f'
     html = gethtml(url)
     MAX_COUNT = 3
     class_url_list = crawlingClassid(html)
     threads = []
     for i,url in zip(range(len(class_url_list)), class_url_list):
         pattern_class = r'courseId=(.*?)&clazzid=(.*?)&enc'
         regx =  re.search(pattern_class, url)
         courseId, clazzid = regx.group(1), regx.group(2)
         sendMsg(courseId, clazzid, MAX_COUNT)
 if __name__=='__main__':
     managerCrawling()

效果:

python--爬虫--利用cookie登录网络教学中心刷评论的更多相关文章

  1. 用cookie登录慕课网络教学中心刷评论

    声明:本文仅供学习参考 我们学校和的网络教学平台是在慕课网上的,需要登录到慕课网的教学平台以后,拿到cookie 注意:没次提交后需要休眠,否则刷评论过快会被系统发现 如果请求太快,很容易被系统发现( ...

  2. python爬虫-使用cookie登录

    前言: 什么是cookie? Cookie,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密). 比如说有些网站需要登录后才能访问某个页面,在登录之前,你想 ...

  3. python爬虫+使用cookie登录豆瓣

    2017-10-09 19:06:22 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言: 先获得cookie,然后自动登录豆瓣和新浪微博 系统环境: 64位win10系统,同时装pytho ...

  4. Python爬虫之模拟登录微信wechat

    不知何时,微信已经成为我们不可缺少的一部分了,我们的社交圈.关注的新闻或是公众号.还有个人信息或是隐私都被绑定在了一起.既然它这么重要,如果我们可以利用爬虫模拟登录,是不是就意味着我们可以获取这些信息 ...

  5. Python爬虫-百度模拟登录(二)

    上一篇-Python爬虫-百度模拟登录(一) 接上一篇的继续 参数 codestring codestring jxG9506c1811b44e2fd0220153643013f7e6b1898075 ...

  6. js利用cookie登录网站

    如上图,我们获取到了cookie,接下来利用cookie登录相应的网站. 我用的浏览器是火狐,首先在特定的网站(也就是我们发现XSS漏洞的网站,这里指的是pikachu)F12打开开发者工具,找到控制 ...

  7. 1.python+selenium利用cookie,跳过验证码直接登录

    方法1 在登录时,叫代码等待一段时间,然后手动输入验证码 # coding:utf-8 from selenium import webdriver import time url = 'http:/ ...

  8. 【Python爬虫】01:网络爬虫--规则

    Python网络爬虫与信息提取 目标:掌握定向网络数据爬取和网页解析的基本能力. the website is the API 课程分为以下部分: 1.requsets库(自动爬取HTML页面.自动网 ...

  9. Python爬虫之Cookie和Session

    关于cookie和session估计很多程序员面试的时候都会被问到,这两个概念在写web以及爬虫中都会涉及,并且两者可能很多人直接回答也不好说的特别清楚,所以整理这样一篇文章,也帮助自己加深理解 什么 ...

随机推荐

  1. selenium webDriver给隐藏域赋值 input hidden set value

    //直接这样无法给input hidden赋值// driver.findElement(By.id("image_default")).sendKeys("a1112. ...

  2. Entity Framework入门教程: Entity Framework支持的查询方式

    Entity Framework支持的查询方式有三种 LINQ to Entities Entity SQL Native SQL [LINQ to Entities] LINQ(语言集成查询)是从V ...

  3. mybatis介绍与环境搭建

    一.不用纯jdbc的原因,即缺点. 1.数据库理解,使用时创建,不用时释放,会对数据库进行频繁的链接开启和关闭,造成数据库的资源浪费,影响数据库的性能.设想:使用数据库的连接池.2.将sql语句硬编码 ...

  4. 基于Dubbo的分布式事务框架(LCN)

    原文地址:http://原文地址:https://github.com/1991wangliang/transaction 基于Dubbo的分布式事务框架(LCN) 该框架依赖Redis/dubbo/ ...

  5. PHP加密字符串函数(Discuz内置的)

    接触Discuz有一段时间了,一直很喜欢这个论坛程序,确实是一个很不错的程序,灰常值得我们去学习,这里介绍它其中的一个加密函数(含解密)这个加密函数的特点在于,比普通的加密函数多了一个随机密钥 ,可以 ...

  6. zookeeer client 通信协议

    这里主要记录zookeeper client通信协议的.在官方的文档里没找到协议相关部分.这里是记录的协议是通过分析客户端代码得来的. 一.通信流程 客户端发起连接,发送握手包进行timeout协商, ...

  7. [leetcode-623-Add One Row to Tree]

    Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value ...

  8. [leetcode-611-Valid Triangle Number]

    Given an array consists of non-negative integers, your task is to count the number of triplets chose ...

  9. 8.vue的生命周期

    Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.卸载等一系列过程,我们称这是Vue的生命周期.通俗说就是Vue实例从创建到销毁的过程,就是生命周期 ...

  10. PyCharm 教程

    转自:http://blog.csdn.NET/u013088062/article/details/50388329 作者:山在岭就在 之间花了一周多的时间把Pycharm官方帮助文档翻译了一遍,一 ...