集搜客GooSeeker网络爬虫
标题:
网页上时间和文字连起来了,如何只采集时间?
[打印本页]
作者:
thursdayrain
时间:
2022-5-29 17:56
标题:
网页上时间和文字连起来了,如何只采集时间?
任务名:印尼文教部_消息_列表
[attach]15511[/attach]
作者:
Fuller
时间:
2022-5-29 18:14
要自定义xpath,在xpath中使用substring-before()函数,而且一定要用专用定位模式。
为了自定义xpath,要做下面几步:
第一:把自动生成的xpath拷贝出来
如下图,点击测试按钮,在采集规则那里找到那个抓取内容,引号内的部分是xpath,拷贝出来。
[attach]15512[/attach]
第二:编辑xpath
自动生成的xpath是这个:
following-sibling::small[position()=1]//*[@class='date']
复制代码
一定要在自动生成的xpath基础上编辑,因为自动生成的xpath会考虑抓取内容与整理箱的相对位置。手工编辑以后,是这样的:
substring-before(following-sibling::small[position()=1]//*[@class='date']/text(), ', ')
复制代码
自动生成的xpath放在定位xpath那里,内容xpath那里放手工编辑好的。因为要截取字符串,所以,一定要专用定位,截取字符串的那个xpath不能用户定位。
[attach]15513[/attach]
欢迎光临 集搜客GooSeeker网络爬虫 (https://www.gooseeker.com/doc/)
Powered by Discuz! X3.2