File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ def parse1(self, response):
3838 items .append (item )
3939
4040 #根据每个章节的链接,发送Request请求,并传递item参数
41- for item in items :
41+ for item in items [ - 13 : - 1 ] :
4242 yield scrapy .Request (url = item ['link_url' ], meta = {'item' :item }, callback = self .parse2 )
4343
4444 #解析获得章节第一页的页码数和图片链接
@@ -57,7 +57,7 @@ def parse2(self, response):
5757 #返回item,交给item pipeline下载图片
5858 yield item
5959 #获取章节的页数
60- page_num = hxs .xpath ('//td[@valign="top"]/text()' ).re (u'共(\d+)页' )[0 ]、
60+ page_num = hxs .xpath ('//td[@valign="top"]/text()' ).re (u'共(\d+)页' )[0 ]
6161 #根据页数,整理出本章节其他页码的链接
6262 pre_link = item ['link_url' ][:- 5 ]
6363 for each_link in range (2 , int (page_num ) + 1 ):
@@ -69,6 +69,8 @@ def parse2(self, response):
6969 def parse3 (self , response ):
7070 #接收传递的item
7171 item = response .meta ['item' ]
72+ #获取该页面的链接
73+ item ['link_url' ] = response .url
7274 hxs = Selector (response )
7375 pre_img_url = hxs .xpath ('//script/text()' ).extract ()
7476 #注意这里返回的图片地址,应该为列表,否则会报错
You can’t perform that action at this time.
0 commit comments