python - scrapy爬蟲不能循環(huán)運行?
問題描述
scrapy只能爬取一個頁面上的鏈接,不能持續(xù)運行爬完全站,以下是代碼,初學(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. 求大神支招,php怎么操作在一個html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?2. 安裝了“PHP工具箱”,但只能以“游客”身份登錄3. 老師們php,插入數(shù)據(jù)庫mysql,都是空的,要怎么解決4. 跨類調(diào)用后,找不到方法5. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現(xiàn)存在即更新應(yīng)該使用哪個標(biāo)簽?6. 致命錯誤: Class ’appfacadeTest’ not found7. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項8. PHP類屬性聲明?9. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。10. phpstady在win10上運行
