1つのWebサイトをクロールしますが、次のページをクロールすると機能しません。ここにスパイダーコードがありますか?どこが間違っていますか教えてください、ありがとうございます。次のページでの巡回クロールは機能しません
import scrapy
from crawlAll.items import CrawlallItem
class ToutiaoEssayJokeSpider(scrapy.Spider):
name = "duanzi"
allowed_domains = ["http://duanziwang.com"]
start_urls = ['http://duanziwang.com/category/duanzi/page/1']
def parse(self, response):
for sel in response.xpath("//article[@class='excerpt excerpt-nothumbnail']"):
item = CrawlallItem()
item['Title'] = sel.xpath("//header/h2/a/text()").extract_first()
item['Text'] = sel.xpath("//p[@class='note']/text()").extract_first()
item['Views'] = sel.xpath("//p[1]/span[@class='muted'][2]/text()").extract_first()
item['Time'] = sel.xpath("//p[1]/span[@class='muted'][1]/text()").extract_first()
yield item
next_page = response.xpath("//ul/li[@class='next-page']/a/@href").extract_first()
if next_page is not None:
next_page = response.urljoin(next_page)
yield scrapy.Request(next_page, callback=self.parse)
私は本当かどう場合にnext_page値をテストするために、印刷(にnext_page)を使用している、そしてそれは本当だ、それは私にこのようなリンクアドレス与える:http://duanziwang.com/category/duanzi/page/2」を、何が私のコードが悪いですの?
あなたのクロールからコンソールログを共有できますか? (最後の統計情報付き) –