【问题标题】:how to get text value of title attribute of anchor tag in python?如何在python中获取锚标记的标题属性的文本值?
【发布时间】:2017-10-25 17:39:56
【问题描述】:

从下面的代码如何获取标题文本

<td class="col_name" nowrap="nowrap">
<a class="icon" title="refer me">
<img src="https://edu.au/images/icons/silk/vcard.gif" align="top" 
alt="Add to address book">
</a>
Mrs Cal <span class="hl_fcc">B</span>AREN
</td>

即,在python中使用scrapy推荐我吗?请有人能回答这个问题吗?我试过 response.css('td.col-name a::attr(text)').extract()..但我得到“[]”

【问题讨论】:

    标签: python-2.7 scrapy


    【解决方案1】:

    使用 CSS:

    response.css('td.col_name a::attr(title)').extract_first()
    

    使用 XPath:

    response.xpath('//td[@class="col_name"]/a/@title').extract_first()
    

    【讨论】:

      猜你喜欢
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多