爬豆瓣影评,记下解决maximum recursion depth exceeded in cmp
#主要是爬取后给别人做自然语言分析,没其他意思。 #coding=utf8
import requests,re
from lxml import etree import sys
reload(sys)
sys.setdefaultencoding('utf8') sys.setrecursionlimit() #解决maximum recursion depth exceeded in cmp
def craw(url):
headerx={
'Cookie':'bid=OIBtzThxxA; ct=y; _pk_ref.100001.4cf6=%5B%22%22%2C%22%22%2C1502186407%2C%22http%3A%2F%2Fqianxun.baidu.com%2Fmovie%2Fcard_2162.html%22%5D; __utmt=1; ps=y; dbcl2="165xxx93:UV/wbzXasBQ"; ck=d-ep; _pk_id.100001.4cf6=7bff167cf6dxxxxxx.10.1502186411; __utmc=30149280; __utmz=30149280.1501649654.7.7.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; __utma=22369xxxxx59553.1502186411.2; __utmb=223695111.48.10.1502186411; __utmc=223695111; __utmz=223695111.1500959553.1.1.utmcsr=qianxun.baidu.com|utmccn=(referral)|utmcxxxxx.html; push_noty_num=0; push_doumail_num=0; ap=1'
}
while :
try:
resp=requests.get(url,headers=headerx)
if resp.status_code==:
flag=
break
else:
pass
except Exception,e:
print e selector=etree.HTML(resp.content.decode('utf8')) #print resp.content.decode('utf8')
all_comment=selector.xpath('//div[@class="comment-item"]')
for comment in all_comment:
#print etree.tounicode(comment),'************************'
star_class=comment.xpath('.//span[contains(@class,"allstar")]/@class')
if star_class:
starx=re.findall('tar(.*?)0',star_class[])[]
else:
starx= #有的评论没有打星
textx=comment.xpath('.//div[@class="comment"]/p/text()')[]
print starx,'星 ',textx f.write('%s星 %s\r\n'%(starx,textx)) next_start=re.search(u'前页[\s\S]*?<a href="\?start=(.*?)&[\s\S]*?后页',resp.content.decode('utf8')).group()
next_url='https://movie.douban.com/subject/25662329/comments?start=%s&limit=20&sort=new_score&status=P'%next_start
print '爬取下一页:',next_url
craw(next_url) ####这行调用自己 if __name__=="__main__":
f = open('pinlun.txt', 'a')
craw('https://movie.douban.com/subject/25662329/comments?start=71726&limit=20&sort=new_score&status=P')
豆瓣的影评,每一页的页面链接不是可以预知的,url中start从0开始,第二页是20,第三页是40,这是理想状态,但真实不是这样。所以要从网页中提取下一页的链接,单线程,自己调用自己,每爬了几十分钟后报错maximum recursion depth exceeded in cmp,以为是个偶然,反复把脚本停了再重启了好几次都是这样,就找下答案了,上面是函数里面有个调用函数本身的代码,反复的调用自己,这种次数不能超过900,设置了sys.setrecursionlimit=100000果然好了。
爬豆瓣影评,记下解决maximum recursion depth exceeded in cmp的更多相关文章
- 记 suds 模块循环依赖的坑-RuntimeError: maximum recursion depth exceeded
下面是soa接口调用的核心代码 #! /usr/bin/python # coding:utf-8 from suds.client import Clientdef SoaRequest(wsdl, ...
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
当你的程序递归的次数超过999次的时候,就会引发RuntimeError: maximum recursion depth exceeded. 解决方法两个: 1.增加系统的递归调用的次数: impo ...
- Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison
Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in compa ...
- python maximum recursion depth exceeded 处理办法
1.在执行命令 pyinstaller -F D:\py\programe\banksystem.py打包生成.exe文件时报错:python maximum recursion depth exce ...
- Odoo8查询产品时提示"maximum recursion depth exceeded while calling a Python object"
今天在生产系统中查询产品时,莫名提示错误:maximum recursion depth exceeded while calling a Python object,根据错误日志提示,发现在查询产品 ...
- scrapy RuntimeError: maximum recursion depth exceeded while calling a Python object 超出python最大递归数异常
2019-10-21 19:01:00 [scrapy.core.engine] INFO: Spider opened2019-10-21 19:01:00 [scrapy.extensions.l ...
- python --RecursionError: maximum recursion depth exceeded in comparison
在学习汉娜塔的时候,遇到一个error RecursionError: maximum recursion depth exceeded in comparison 经过百度,百度的方法: 加上: i ...
- python 报错:RecursionError: maximum recursion depth exceeded
RecursionError:maximun recursion depth exceeded 超过了最大递归深度 原因: 在使用@property装饰器时,方法名与实例的属性同名,在赋值进从而产生了 ...
- pyinstaller打包报错: RecursionError: maximum recursion depth exceeded 已经解决
看上去似乎是某个库自己递归遍历超过了python的栈高度限制 搜索了一番,很快找到了解决办法: https://stackoverflow.com/questions/38977929/pyinsta ...
随机推荐
- Mongodb网络好文章
http://blog.csdn.net/pi9nc/article/details/17722419 mongodb集群配置. http://blog.fens.me/mongodb-replica ...
- PowerDesigner使用教程【转】
PowerDesigner使用教程 —— 概念数据模型 一.概念数据模型概述 概念数据模型也称信息模型,它以实体-联系(Entity-RelationShip,简称E-R)理论为基础,并对这 ...
- 如何在CentOS 6.5上升级PHP
CentOS 6.5上默认安装PHP 5.3.因为后台网站无法正确运行在PHP 5.3上,所以计划将PHP升级到开发平台一样的版本PHP 5.5.为了方便,我们采用YUM的方式升级PHP 工具/原料 ...
- SQLServer 错误: 15404,无法获取有关 Windows NT 组
右击-属性-所有者改成sa 测试一下 右击 --- 作业开始步骤---执行成功
- Android开发 listitem中采用倒计时
采用单个倒计时控件会紊乱,故采用在activity中倒计时异步刷新通知的方式全局更新数据源 notifyDataSetChanged 效果如下: 大致思路: 若出现刷新倒计时有的显示有的不显示的情况 ...
- jspSmartUpload使用初步
jsp中使用SmartUpload上传文件 1.下载jspSmartUpload组件后,解压缩.把com目录复制到应用程序的WEB-INF\classes目录下. 2.尤其注意 (1)文件上传表单要添 ...
- 小米3移动版 分区 调整/合并教程(16GB/64GB)
(必读)版权声明:米3移动版TWRP Recovery为XueferH适配,分区脚本以及双数据置换脚本的知识产权,智力成果权归XueferH所有. 注:此教程仅适用于Xiaomi MI 3-移动版(1 ...
- 如何将Mac系统OS X Yosemite装到外部磁盘?(转)
有Mac用户想了解是否可以将 OS X Yosemite 装到替代的外部磁盘,答案是肯定的,有需求的用户,可以按照本篇教程逐步进行. 前面我已经写过一篇文章介绍了如何安装 OS X Yosemite ...
- android sqlite blob
BOLB表示二进制大对象,这种数据类型通过用来保存图片,图象,视频等. 使用场景: http://blog.sina.com.cn/s/blog_8cfbb99201012oqn.html publi ...
- 成都传智播客java就业班(14.04.01班)就业快报(Java程序猿薪资一目了然)
这是成都传智播客Java就业班的就业情况,很多其它详情请见成都传智播客官网:http://cd.itcast.cn?140812ls 姓名 入职公司 入职薪资(¥) 方同学 安**软件成都有限公司(J ...