以圖靈社區每週特價頁面爲例: https://www.ituring.com.cn/tag/36527
html
這個頁面每週一都會更新三個半價電子書,先分析頁面xpath,找出規律.web
複製後粘貼,能夠看到三本書的xpath分別是:url
//*[@id="tag-book"]/div/ul/li[1]/div[2]/h4/a
spa
//*[@id="tag-book"]/div/ul/li[2]/div[2]/h4/a
code
//*[@id="tag-book"]/div/ul/li[3]/div[2]/h4/a
htm
只有中間的li[]
內容不同.blog
所以options部分,xpath部分能夠用li[*]
匹配全部狀況.能夠這樣寫:it
{ "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部分:io
{ "webhook_url": "https://hooks.slack.com/services/xxxx/xxxxxxxx", "channel": "#book", "username": "Huginn", "message": "{{title}} https://www.ituring.com.cn{{url}}", "icon": "" }