python - scrapy爬虫不能循环运行?
问题描述
scrapy只能爬取一个页面上的链接,不能持续运行爬完全站,以下是代码,初学求指导。
class DbbookSpider(scrapy.Spider): name = 'imufe' allowed_domains = [’http://www.imufe.edu.cn/’] start_urls=(’http://www.imufe.edu.cn/main/dtxw/201704/t20170414_127035.html’) def parse(self, response):item = DoubanbookItem()selector = scrapy.Selector(response)print(selector)books = selector.xpath(’//a/@href’).extract()link=[]for each in books: each=urljoin(response.url,each) link.append(each)for each in link: item[’link’] = each yield itemi = random.randint(0,len(link)-1)nextPage = link[i]yield scrapy.http.Request(nextPage,callback=self.parse)
问题解答
回答1:是不是爬得太快让封了
相关文章:
1. javascript - 单页面应用怎么监听ios微信返回键?2. angular.js - 在ionic下,利用javascript导入百度地图,pc端可以显示,移动端无法显示3. vue.js - vue apache 代理设置4. javascript - avalon使用:duplex设置select默认option的bug5. html - 类似这样的弹层用什么插件写比较好?6. html - css布局问题,背景用用div画的三角形是否用absolute与z-index来定位与规定在下方是否是个好方案7. html - IOS二维码识别问题8. angular.js - 百度支持_escaped_fragment_吗?9. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?10. node.js - Vue+Webpack在dev环境下没有问题build后出现莫名错误
