0

我想选择标签中包含的所有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() ,但结果是:[]

4

2 回答 2

0

建议您使用 xpath 表达式。对于你的例子response.xpath("//a[class='aok-block aok-nowrap']").get_attribute('href')

于 2018-11-28T16:14:29.453 回答
0

添加到答案 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()
于 2018-11-29T09:40:23.620 回答