没有定义python scrapy get_attribute

时间:2014-01-14 18:17:11

标签: python xpath scrapy

我想获得href代码的<a>

我试过了;

def parse(self, response):
        sel = Selector(response)
        sites = sel.xpath('.//div[@class="aaaaaaaaaa"]/h3/span/a')
        for site in sites:
            Link = site.get_attribute('href')
            print Link

但我知道了:

请帮忙      exceptions.AttributeError:'Selector'对象没有属性'get_attribute

1 个答案:

答案 0 :(得分:3)

你可以这样做:

def parse(self, response):
    sel = Selector(response)
    sites = sel.xpath('.//div[@class="block item-title"]/h3/span/a')
    for site in sites:
        Link = site.xpath('@href').extract()[0]
        print Link