Huginn監測網頁變化並推送

以圖靈社區每週特價頁面爲例: https://www.ituring.com.cn/tag/36527html

抓取內容

這個頁面每週一都會更新三個半價電子書,先分析頁面xpath,找出規律.
image.pngweb

複製後粘貼,能夠看到三本書的xpath分別是:url

//*[@id="tag-book"]/div/ul/li[1]/div[2]/h4/aspa

//*[@id="tag-book"]/div/ul/li[2]/div[2]/h4/acode

//*[@id="tag-book"]/div/ul/li[3]/div[2]/h4/ahtm

只有中間的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": ""
}

效果

image.png

相關文章
相關標籤/搜索