爬豆瓣影评,记下解决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 ...
随机推荐
- 负数在计算机中的表示 Byte-128
本文转载: http://blog.csdn.net/njuitjf/article/details/4585247 原码:将一个整数,转换成二进制,就是其原码.如单字节的5的原码为:0000 010 ...
- sql 拼接同列的值
sql中有时需要将列的值转成行的形式,比如下面的数据,具有相同Path的ZumenID有哪一些,该怎么做呢? 常见的做法可以参见这篇文章http://www.cnblogs.com/xiashengw ...
- 什么是API网关?
版权声明:本文为博主原创文章,未经博主允许不得转载. http://blog.csdn.net/lcx216/article/details/52913645 1.API网关介绍 API网关是一个服务 ...
- Spring面试问题集锦
Q. 对于依赖倒置原则(Dependency Inversion Principle,DIP),依赖注入(Dependency Injection,DI)和控制反转(Inversion of Cont ...
- 关于sentinel LDK加密war包实现应用加密的使用方法
经过一周多时间的研究,终于对sentinel产品的使用有个基本的掌握.其中走了不少的弯路,特此记录一下,以备后面回顾. 开发前的用料准备: windows 10 x64位, tomcat7 x64bi ...
- R语言 ggplot2 画平滑图
library(splines) library(ggplot2) dt1 <- structure(list(Age = structure(c(1L, 1L, 1L, 1L, 1L, 1L, ...
- R语言包_dplyr_1
有5个基础的函数: - filter - select - arrange - mutate - summarise - group_by (plus) 可以和databases以及data tabl ...
- 使用VMware将Linux装在物理硬盘上,开机即可进入Linux (转)
目录(?)[-] 本文目的 具体操作 1 软件准备 2 安装 21 对硬盘操作 22 创建虚拟机并安装 23 使用Grub引导Linux 1. 本文目的 适合于没有光驱的计算机来安装Linux,还有 ...
- error: navicat 连接debian系列系统mysql 10038问题解决方案
还特么有一种可能 阿里云 也有防火墙出口入口规则,这里也有问题
- python程序中的调试:pdb
python中,也有像c/c++语言的 gdb 一样的调试程序,即pdb: 只简单说明一个怎么使用它. 假设已经有了一个python程序名为 test.py, 我们在命令行输入以下内容,即可以进行 p ...