以图灵社区每周特价页面为例: https://www.ituring.com.cn/tag/36527
抓取内容
这个页面每周一都会更新三个半价电子书,先分析页面xpath,找出规律.
复制后粘贴,可以看到三本书的xpath分别是:
//*[@id="tag-book"]/div/ul/li[1]/div[2]/h4/a
//*[@id="tag-book"]/div/ul/li[2]/div[2]/h4/a
//*[@id="tag-book"]/div/ul/li[3]/div[2]/h4/a
只有中间的li[]
内容不一样.
因此options部分,xpath部分可以用li[*]
匹配所有情况.可以这样写:
{
"expected_update_period_in_days": "2",
"url": "https://www.ituring.com.cn/tag/36527",
"type": "html",
"mode": "on_change",
"extract": {
"url": {
"xpath": "//*[@id=\"tag-book\"]/div/ul/li[*]/div[2]/h4/a",
"value": "@href"
},
"title": {
"xpath": "//*[@id=\"tag-book\"]/div/ul/li[*]/div[2]/h4/a",
"value": "@title"
}
}
}
推送内容
使用slack agent推送.
options部分:
{
"webhook_url": "https://hooks.slack.com/services/xxxx/xxxxxxxx",
"channel": "#book",
"username": "Huginn",
"message": "{{title}} https://www.ituring.com.cn{{url}}",
"icon": ""
}