如何获取response.css.xpath仅给我href元素?

时间:2019-07-10 15:43:53

标签: python scrapy

在使用response.css和.xpath时,我不确定如何仅获取元素的Href值。

hrdLink = str(response.css('span.a-button-inner').xpath('//a[contains(@href,"ref=tmm_hrd_swatch")]').extract_first())

这给了我所需的链接,但还附带了很多我需要摆脱的额外数据。

我尝试放

...//a[contains(@href,"ref=tmm_hrd_swatch")]::attr(href)')...

我希望输出只是href值的链接,我查看了拆分输出,但这在不同页面上发生了变化。

0 个答案:

没有答案