调试Scrapy过程中的心得体会
1.大量抓取网页时出现“Memory Error”解决办法:设置一个队列,每当爬虫空闲时才向队列中放入请求,例如:
from scrapy import signals, Spider
from scrapy.xlib.pydispatch import dispatcher class ExampleSpider(Spider):
name = "example"
start_urls = ['http://www.example.com/'] def __init__(self, *args, **kwargs):
super(ExampleSpider, self).__init__(*args, **kwargs)
# connect the function to the spider_idle signal
dispatcher.connect(self.queue_more_requests, signals.spider_idle) def queue_more_requests(self, spider):
# this function will run everytime the spider is done processing
# all requests/items (i.e. idle) # get the next urls from your database/file
urls = self.get_urls_from_somewhere() # if there are no longer urls to be processed, do nothing and the
# the spider will now finally close
if not urls:
return # iterate through the urls, create a request, then send them back to
# the crawler, this will get the spider out of its idle state
for url in urls:
req = self.make_requests_from_url(url)
self.crawler.engine.crawl(req, spider) def parse(self, response):
pass
More info on the spider_idle signal: http://doc.scrapy.org/en/latest/topics/signals.html#spider-idle
More info on debugging memory leaks: http://doc.scrapy.org/en/latest/topics/leaks.html
P.S.还有一种限定爬取深度的方法(貌似在settings.py中?)待研究
2.如果请求的url不存在(404),则不会有response对象返回,爬虫什么也没做
3.编码问题
pubmed_spider.py中
import sys
reload(sys)
#python默认环境编码时ascii
sys.setdefaultencoding("utf-8")
保证抓取到的数据是utf8格式的
pipeline.py中file = codecs.open('/%s.txt' % (item['name']), mode = 'w',encoding='utf-8')将数据以utf8格式存储
调试Scrapy过程中的心得体会的更多相关文章
- xp硬盘安装Fedora14 过程记录及心得体会(fedora14 live版本680M 和fedora14 DVD版本3.2G的选择)
这次电脑奔溃了,奇怪的是直接ghost覆盖c盘竟然不中.之前电脑上硬盘安装的fedora14操作系统,也是双系统.不知道是不是这个问题,记得同学说过,在硬盘装fedora之后,要手动修改c盘隐藏的那个 ...
- 疑问:VS在调试的过程中,总是会提示正在加载picface.dll的符号,然后卡死在那
环境: 硬件环境: PC 软件环境: Windows7 VS2012 MFC程序调试 现象: 调试的过程中,提示“正在从以下目录加载picface.dll的符号:C:\windows\dll”,然后就 ...
- 使用Android Studio调试UiAutomator过程中遇到的问题
声明: 这里纪录了个人学习和使用Android Studio调试UiAutomator过程中遇到遇到的问题,不定时进行更新,欢迎一起交流学习 1.Excution faild for task ‘:a ...
- Python安装scrapy过程中出现“Failed building wheel for xxx”
https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml Python安装scrapy库过程中出现“ Failed building wheel for xxx ...
- 安装Scrapy过程中遇到的几个问题总结
安装Scrapy 1.https://www.lfd.uci.edu/~gohlke/pythonlibs/下载 Twisted 安装 Twisted-19.10.0-cp37-cp37m-win_a ...
- 获取图书isbn信息 共享图书开发 图书信息接口开发过程中的心得体会
最近做一个图书共享的项目,需要用户扫一扫书籍后面的一维码,获取到书籍的isbn号码,然后通过这个isbn号码能够直接获取到这本书的名字.简介.价格.图片等信息. 于是百度搜了下,之前很多的豆瓣的接口, ...
- vs2012 在调试或运行的过程中不能加断点
在使用VS2012 的过程中,突然发现在调试的过程中,不能加断点,显示断点未能绑定.在搜寻了很多解决方案后未能解决,3.23这一天,重装了VS也没有用. 便想着把网上所有的方法都试个遍也要解决这个问题 ...
- Android APP 调试过程中遇到的问题。
调试过过程中APP安装完启动后有的时候会异常退出,报这个错误.有的时候可以直接启动.查找不到原因.网上说把commit方法替换成commitAllowingStateLoss() 也无效. Andro ...
- 百度自动发贴,登录很顺利的模拟实现,但发贴攻关失败,能力有限,追JS过程中颇为痛苦
攻关失败,且短期内看不到希望,看不到方向,且越来越焦急,目前已知的是,用根据用户的鼠标事件以一定的规则结合其他数据,服务器以这些数据验证是否为真正的手动发贴. 不过闲暇时实现了百度贴吧的自动签到. 较 ...
随机推荐
- configurationmanager.getsection usage
public static void CreateAppSettings() { // Get the application configuration file. System.Configura ...
- [LeetCode] Path Sum II 深度搜索
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---31
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- LeetCode OJ--Palindrome Number
https://oj.leetcode.com/problems/palindrome-number/ 判断是否为回文数 取每一位存到vector中,再判断 负数不是回文数 class Solutio ...
- LeetCode OJ--Combination Sum **
https://oj.leetcode.com/problems/combination-sum/ 给一列数,3 2 1 3 3 8 7 9 ,每个数可以重复多次,给target 7, 问可以加起来得 ...
- SSH架构BaseDao实现
package cn.itcast.dao; import java.io.Serializable; import java.util.List; /** * BaseDao * @author A ...
- Centos python 2.6 升级到 2.7
前几天做了下阿里云的RDS日志相关功能,其工具大都是Python语言编写,但服务器初始化时的Python版本又不满足需求,本身也没有学过Python,因此在问题定位上费了一番周折,最后找朋友帮忙看了下 ...
- (18) python 爬虫实战
一切从最简单开始 峰绘网 :http://www.ifenghui.com/ 一个比较好爬的漫画网,之所以选择这个网站,因为查看源代码能直接获得漫画的jpg连接,而且每一话所有的jpg一次性的都展示出 ...
- TopCoder SRM 722 Div1 Problem 600 DominoTiling(简单插头DP)
题意 给定一个$12*12$的矩阵,每个元素是'.'或'X'.现在要求$1*2$的骨牌铺满整个矩阵, 'X'处不能放置骨牌.求方案数. 这道题其实和 Uva11270 是差不多的,就是加了一些条件. ...
- 提升开发效率的一款mybatis开发神器
文末附有完整案例的代码内容!! 以前在开发的时候,使用mybatis的时候,经常都需要先配置xml映射文件,然后每条sql操作都需要自己进行手动编写,对于一些复杂的sql这么来操作确实有必要,但是如果 ...