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 - sublime怎么支持webp的浏览?2. javascript - nginx 反向代理 js跨域问题?3. css3 - img垂直水平居中问题4. python - pig latin问题 总是出现list/string index out of range5. javascript - sublime已经安装了babel插件和sublimelinter-jshint为什么还是显示es6语法错误?6. html5 - 为什么浏览器可以显示HTML文档中未被定义的标签?7. javascript - 图片能在网站显示,但控制台仍旧报错403 (Forbidden)8. javascript - angularJS select标签问题9. 安装mysql,完成时提示的是用户名root,在终端查看版本时显示的不是root,请问这怎么解决10. python - 如何解决程序运行太久之后被操作系统暂停的情况?

网公网安备