4.2.5任务类
package com.tensquare.usercrawler.task;import com.tensquare.usercrawler.pipeline.UserPipeline; import com.tensquare.usercrawler.processor.UserProcessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled;import org.springframework.stereotype.Component;import us.codecraft.webmagic.Spider;import us.codecraft.webmagic.scheduler.RedisScheduler;/*** 用户爬取任务类*/ @Componentpublic class UserTask {@Autowiredprivate RedisScheduler redisScheduler;@Autowiredprivate UserPipeline userPipeline;@Autowiredprivate UserProcessor userProcessor;/*** 爬取用户数据*/@Scheduled(cron="0 56 22 * * ?") public void userTask(){System.out.println("爬取用户");Spider spider = Spider.create(userProcessor); spider.addUrl("https://blog.csdn.net"); spider.addPipeline(userPipeline); spider.setScheduler(redisScheduler); spider.start();}}附录 A XPath语法
(1)选取节点:

文章插图
(2)谓语
谓语用来查找某个特定的节点或者包含某个指定的值的节点 。谓语被嵌在方括号中

文章插图
(3)通配符
XPath 通配符可用来选取未知的 XML 元素,通配指定节点 。

文章插图
(4)多路径选择
通过在路径表达式中使用“|”运算符,您可以选取若干个路径 。**

文章插图
(5)XPath 轴
轴可定义相对于当前节点的节点集 。

文章插图

文章插图

文章插图
(6)XPath 运算符

文章插图
(7)常用的功能函数
使用功能函数能够更好的进行模糊搜索

文章插图
【人工智能开发 网络爬虫框架Webmagic】
推荐阅读
- 5G手机的发射功率,到底能有多大?
- 什么是JVM?
- 网络交换机如何规划,VLAN原理介绍
- 初学者如何区分Html5开发和前端开发
- 网络常见的9大命令
- 开发过程中快速抓包并解析
- 人工智能基础算法
- iOS 14“本地网络”权限是什么,需要开吗?
- Spring框架中的国际化支持
- 网络诈骗200万怎么判刑
