0

我设法使用调试蜘蛛找到了我想要隔离的属性,但我不确定它是否正确地合并到我的蜘蛛中。蜘蛛运行时我没有收到明确的错误消息,所以我想我只是错误地输入了选择器。

我正在爬的网站是“ http://www.smiling-moose.com/events/index.php ”我在调试蜘蛛中输入的路径命令是“response.xpath('//div[@class=" show_sec_button"]/text()')",它会拉出我正在寻找的确切响应。

这是我的蜘蛛:

import scrapy

from smiling_moose.items import SMItem

class Smspider (scrapy.Spider):
    name = "smspider"
    allowed_domains = ["http://www.smiling-moose.com/index.php"]
    start_urls = [
         "http://www.smiling-moose.com/events/index.php",
    ]

def parse(self, response):
    for sel in response.xpath('//div'):
        item = SMItem()
        item['desc'] = response.xpath('//*[@class="show_sec_band"]/text()').extract()

这是我的 Items.py:

import scrapy


class SMItem(scrapy.Item):
    desc = scrapy.Field()

蜘蛛有什么需要改变的吗?如果需要,我可以发布我的命令提示错误。

谢谢

4

1 回答 1

0

首先更改allowed_domains

allowed_domains = ["smiling-moose.com"]

二、退货:

item['desc'] = response.xpath('//*[@class="show_sec_band"]/text()').extract()
yield item
于 2016-02-26T18:24:58.733 回答