2015-07-11 30 views
0

我嘗試使用XPath得到下面的HTML代碼的@content屬性:Xpath的錯誤消息「exceptions.ValueError:無效的XPath:」

<meta content="52222" name="DCSext.job_id"> 

我用這個XPath代碼scrapy蜘蛛的一部分:

def parse(self, response): 
    hxs = HtmlXPathSelector(response) 
    sites = hxs.select('//*')  

    for site in sites: 
     il = DataItemLoader(response=response, selector=site) 
     il.add_xpath('listing_id', 'meta[@name="DCSext.job_id"]@content') 
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     il.add_xpath('loc_pj', substring-after('h1[@class="title heading"]/text()',':')) 
     il.add_xpath('title', 'head/title/text()') 
     il.add_xpath('post_date', 'div[@id="extr"]/div/dl/dd[3]/text()') 
     il.add_xpath('web_url', 'head/link[@rel="canon"]@href') 
     yield il.load_item()  

我的下劃線代碼的錯誤消息:

exceptions.ValueError: Invalid XPath: meta[@name="DCSext.job_id"]@content 

如何解決這一問題?非常感謝!

回答

1

正確的代碼應該是:

meta[@name="DCSext.job_id"]/@content 
         ^