lichanglin1987 发表于 2020-7-21 14:42:48

关于scrapy问题

这是items.py代码

import scrapy



class CeshiItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    prince = scrapy.Field()
    bookname = scrapy.Field()



这是我的spider.py代码

# -*- coding: utf-8 -*-
import scrapy
from ceshi.items import CeshiItem

class BookSpider(scrapy.Spider):
    name = 'book'
    allowed_domains = ['https://market.douban.com/']
    start_urls = ['https://market.douban.com/book/?utm_campaign=book_freyr_section&utm_source=douban&utm_medium=pc_web&page=1&page_num=18&']

    def parse(self, response):
      bookItem = []
      item = CeshiItem(scrapy.Item)
      booklist = response.xpath('//div[@class="panel-detail"]')
      for each in booklist:
            item['prince'] = each.xpath('./span[@class="book-price"]/i/text()').extracrt()
            item['bookname'] = each.xpath('./div[@class="book-brief"]/h3/text()').extract()

            bookItem.append(item)

      return bookTtem

为啥我最后模拟得出来的是个空列表。哪里出问题了吗

lichanglin1987 发表于 2020-7-21 17:33:19

有大神来帮助一下我吗

lichanglin1987 发表于 2020-7-22 07:59:32

??有人吗

Twilight6 发表于 2020-7-22 17:54:04


数据匹配有问题吧,去调试看看
页: [1]
查看完整版本: 关于scrapy问题