如何提取通过XPath的部分出的源代码scrapy?

问题描述 投票:0回答:1

我想在一节中提取出文字网站的源代码。

我试图提取该网站的源代码如下所示:

if ('function' === typeof window.ToggleFilters) {
    window.ToggleFilters();
}
</script>

<main id="main" data-danger="">

<section data-creation-date="2018-10-15 11:35:06">

    <div class="detail__content">

我已经通过response.css和response.xpath试图尝试获取数据出来的源代码通过scrapy外壳没有运气。

response.xpath("//*[contains('data-creation')]")

我想只提取数据,创建日期,因此看起来像

'2018-10-15 11:35:06'
python scrapy scrapy-shell
1个回答
2
投票
response.css('#main section::attr("data-creation-date")').extract_first()

要么

response.xpath("//@data-creation-date").extract_first()

要么

response.xpath("//main/section/@data-creation-date").extract_first()
© www.soinside.com 2019 - 2024. All rights reserved.