如何通过 xpath 从 scrapy 的源代码中提取部分?
How to extract section via xpath out of source code in scrapy?
我正在尝试从网站的某个部分的源代码中提取文本。
我要提取的站点的源代码如下所示:
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 shell.
从源代码中获取数据,但没有成功
response.xpath("//*[contains('data-creation')]")
我只想提取数据创建日期,这样它看起来像
'2018-10-15 11:35:06'
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()
我正在尝试从网站的某个部分的源代码中提取文本。
我要提取的站点的源代码如下所示:
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 shell.
从源代码中获取数据,但没有成功response.xpath("//*[contains('data-creation')]")
我只想提取数据创建日期,这样它看起来像
'2018-10-15 11:35:06'
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()