#主要是爬取后给别人做自然语言分析,没其他意思。

#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=(.*?)&amp[\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的更多相关文章

  1. 记 suds 模块循环依赖的坑-RuntimeError: maximum recursion depth exceeded

    下面是soa接口调用的核心代码 #! /usr/bin/python # coding:utf-8 from suds.client import Clientdef SoaRequest(wsdl, ...

  2. python递归深度报错--RuntimeError: maximum recursion depth exceeded

    当你的程序递归的次数超过999次的时候,就会引发RuntimeError: maximum recursion depth exceeded. 解决方法两个: 1.增加系统的递归调用的次数: impo ...

  3. Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison

    Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in compa ...

  4. python maximum recursion depth exceeded 处理办法

    1.在执行命令 pyinstaller -F D:\py\programe\banksystem.py打包生成.exe文件时报错:python maximum recursion depth exce ...

  5. Odoo8查询产品时提示"maximum recursion depth exceeded while calling a Python object"

    今天在生产系统中查询产品时,莫名提示错误:maximum recursion depth exceeded while calling a Python object,根据错误日志提示,发现在查询产品 ...

  6. 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 ...

  7. python --RecursionError: maximum recursion depth exceeded in comparison

    在学习汉娜塔的时候,遇到一个error RecursionError: maximum recursion depth exceeded in comparison 经过百度,百度的方法: 加上: i ...

  8. python 报错:RecursionError: maximum recursion depth exceeded

    RecursionError:maximun recursion depth exceeded 超过了最大递归深度 原因: 在使用@property装饰器时,方法名与实例的属性同名,在赋值进从而产生了 ...

  9. pyinstaller打包报错: RecursionError: maximum recursion depth exceeded 已经解决

    看上去似乎是某个库自己递归遍历超过了python的栈高度限制 搜索了一番,很快找到了解决办法: https://stackoverflow.com/questions/38977929/pyinsta ...

随机推荐

  1. 【css】清除浮动(clearfix 和 clear)的用法

    本文主要是讲解如何在 html 中使用 clearfix 和 clear,针对那些刚开始了解 css 的童鞋.关于 clearfix 和 clear 的样式在这里我就不写了,具体样式点击此处. 下面就 ...

  2. Spring Cloud Sleuth Zipkin - (2)

    在上一节<spring-cloud-sleuth+zipkin追踪服务实现(一)>中,我们使用zipkin-server.provider.consumer三个程序实现了使用http方式进 ...

  3. SpringBoot2 JPA No Identifier specified for entity的解决办法

    No Identifier specified for entity的错误 此类注解都在 import javax.persistence.*;包下     @Id     @GeneratedVal ...

  4. v8是怎么实现更快的 await ?深入理解 await 的运行机制

    最近v8团队发表一篇博客Faster async functions and promises, 预计在v7.2版本实现更快的异步函数和promise. 文章内容看起来不是很容易理解,背后的原理比较隐 ...

  5. Microsoft Azure

    Service Bus - Event Hub - Event Hubs Programming Guide - Service Bus Event Hubs Getting Started (Sam ...

  6. 数据框排序 data.frame order

    # sorting examples using the mtcars datasetattach(mtcars) # sort by mpgnewdata <- mtcars[order(mp ...

  7. R语言-分组统计

    分组统计 1.假定有一组成绩数据,要求根据性别进行分组统计: > score    ID   score1 score2 Gender1  101 11.35321    0.9   male2 ...

  8. 【转载】Exchange 2010配置与安装实用手册

    Exchange 2010配置与安装实用手册 在Exchange 2010配置的时候主要分三大部分,这分别是网络配置.准备存储以及相关的安装策略和过程.同时还需要注意和其他的Windows软件相协调. ...

  9. android 8 wifi wifi 扫描过程

    查看一下android wifi扫描的过程. packages\apps\Settings\src\com\android\settings\wifi\WifiSettings.java public ...

  10. Xcode快捷键--灰常实用的快捷键,以后编程快捷多了

    从雨痕老大的博客上转来的 http://www.rainsts.net/article.asp?id=1066 读书人偷书不算窃 :)   1. 文件 CMD + N: 新文件CMD + SHIFT ...