這裏是我的蜘蛛:scrapy:爲什麼沒有用parse_item功能
import scrapy
import urlparse
from scrapy.http import Request
class BasicSpider(scrapy.Spider):
name = "basic2"
allowed_domains = ["cnblogs"]
start_urls = (
'http://www.cnblogs.com/kylinlin/',
)
def parse(self, response):
next_site = response.xpath(".//*[@id='nav_next_page']/a/@href")
for url in next_site.extract():
yield Request(urlparse.urljoin(response.url,url))
item_selector = response.xpath(".//*[@class='postTitle']/a/@href")
for url in item_selector.extract():
yield Request(url=urlparse.urljoin(response.url, url),
callback=self.parse_item)
def parse_item(self, response):
print "+=====================>>test"
這裏是輸出: 2016年8月12日14時46分二十〇秒[scrapy] INFO :蜘蛛打開
2016-08-12 14:46:20 [scrapy]信息:已檢索0頁(在0頁/分鐘),刮0項(在0項/分鐘)
2016-08-12 14: 46:20 [scrapy] DEBUG:Telnet控制檯正在監聽
127.0.0.1:6023 2016-08-12 14:46:20 [scrapy] DEBUG:Crawled(200)http://www.cnblogs.com/robots.txt>(referer:無)
2016-08-12 14:46: 20 [scrapy] DEBUG:Crawled(200)http://www.cnblogs.com/kylinlin/>(referer:無)
2016-08-12 14:46:20 [scrapy] DEBUG:過濾異地請求到' www.cnblogs.com':http://www.cnblogs.com/kylinlin/default.html?page=2>
2016-08-12 14:46:20 [scrapy]信息:關閉蜘蛛(完成)
2016年8月12日十四時46分20秒[scrapy] INFO:傾倒Scrapy統計:
{ '下載/ request_bytes':445,
'下載/ REQUEST_COUNT':2,
'下載/ request_method_count/GET' :2,
'下載/ response_bytes':5113,
'下載/ response_count':2,
'下載/ response_status_count/200':2,
'finish_reason': '完成',
'finish_time':datetime.datetime (2016,8,12,6,46,20,420000),
'log_count/DEBUG':4,
'log_count/INFO':7,
'異地/域':1,
「異地/ filtered':11,
'request_depth_max':1,0
'response_received_count':2,
'sc heduler /出列':1,
'調度器/出列/存儲器':1,
'調度器/排隊':1,
'調度器/入隊/存儲器':1,
'START_TIME':datetime.datetime (2016,8,12,6,46,20,131000)}
2016年8月12日14時46分20秒[scrapy] INFO:蜘蛛閉合(成品)
爲什麼抓取網頁是0? 我不明白爲什麼沒有輸出像「+ =====================」測試「。 有人可以幫我嗎?
非常感謝你 –