python - scrapy爬蟲不能循環(huán)運(yùn)行?
問題描述
scrapy只能爬取一個(gè)頁面上的鏈接,不能持續(xù)運(yùn)行爬完全站,以下是代碼,初學(xué)求指導(dǎo)。
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:是不是爬得太快讓封了
相關(guān)文章:
1. mysql優(yōu)化 - 關(guān)于mysql分區(qū)2. javascript - ionic2 input autofocus 電腦成功,iOS手機(jī)鍵盤不彈出3. node.js - 在vuejs-templates/webpack中dev-server.js里為什么要exports readyPromise?4. java - Atom中文問題5. java - MySQL中,使用聚合函數(shù)+for update會(huì)鎖表嗎?6. 請(qǐng)教各位大佬,瀏覽器點(diǎn) 提交實(shí)例為什么沒有反應(yīng)7. objective-c - iOS開發(fā)支付寶和微信支付完成為什么跳轉(zhuǎn)到了之前開發(fā)的一個(gè)app?8. html5 - 如何實(shí)現(xiàn)帶陰影的不規(guī)則容器?9. vue.js - vue 打包后 nginx 服務(wù)端API請(qǐng)求跨域問題無法解決。10. javascript - 為什么這個(gè)點(diǎn)擊事件需要點(diǎn)擊兩次才有效果
