我想选择标记中包含的所有href。。。这是我的html代码
<a href="/gp/product/0545935172 ...." class="aok-block aok-nowrap" title="Dog Man: Lord of the Fleas: From the Creator of Captain Underpants (Dog Man #5)">
我使用了response.css('a.aok-block::attr(href)').extract()
但结果是:[]
建议您使用xpath表达式。例如response.xpath("//a[class='aok-block aok-nowrap']").get_attribute('href')
添加到答案johnnydoe
将是:
response.xpath('*//a/@href').extract_first()
response.xpath('*//a/@class').extract_first()
response.xpath('*//a/@title').extract_first()
如果你只想得到href,那么你必须找到上面的标签。。。像这样:
<li>
<a id="nav-questions" href="/questions">
</li>
将是:
response.xpath('...some uniq selector.../li/a/@href').extract_first()