爬虫技术(02)神箭手爬虫实时API
生活随笔
收集整理的這篇文章主要介紹了
爬虫技术(02)神箭手爬虫实时API
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
var scanUrl = "http://www.leiphone.com/news/201610/9EbxjV73a9kGhN3a.html"
;//@input(scanUrl, 文章url, 請(qǐng)輸入正確的url)var configs = {domains: ["leiphone.com"],scanUrls: [scanUrl],fields: [{// 抽取文章頁面的標(biāo)題name: "article_title",selector: "//h1[contains(@class,'headTit')]",required: true},{// 抽取文章頁面的內(nèi)容name: "article_content",selector: "//div[contains(@class,'lph-article-comView')]",required: true},{// 抽取文章頁面的發(fā)布日期name: "article_publish_time",selector: "//td[contains(@class,'time')]",required: true},{// 抽取文章頁面的作者name: "article_author",selector: "//td[contains(@class,'aut')]/a",required: true}]
};// 在"afterExtractField回調(diào)函數(shù)"中將爬取到的時(shí)間轉(zhuǎn)換為秒級(jí)時(shí)間戳
configs.afterExtractField = function(fieldName, data, page, site) {if (fieldName == "article_publish_time") {var timestamp = Date.parse(data);return isNaN(timestamp) ? 0 : parseInt(timestamp/1000);}return data;
};// 使用以上配置創(chuàng)建一個(gè)實(shí)時(shí)API
var fetcher = new Fetcher(configs);
// 運(yùn)行實(shí)時(shí)API
fetcher.start();
總結(jié)
以上是生活随笔為你收集整理的爬虫技术(02)神箭手爬虫实时API的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【您有新的未分配天赋点】网络流:从懵逼到
- 下一篇: SpringCloud Tencent