node.js用get方式获取网页中的链接
生活随笔
收集整理的這篇文章主要介紹了
node.js用get方式获取网页中的链接
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
get方式獲取網頁中的鏈接
var http = require('http');//定義函數(shù) var getAHref = function(htmlstr){var reg = /<a.+?href=('|")?([^'"]+)('|")?(?:\s+|>)/gim;var arr = [];while(tem=reg.exec(htmlstr)){arr.push(tem[2]);}return arr; }var qHref = "http://xxx";//設置被查詢的目標網址var req = http.get(qHref, function(res) {var pageData = "";res.setEncoding('utf8');res.on('error', function (errget) {//出錯處理});res.on('data', function (chunk) {pageData += chunk;});res.on('end', function(){//console.dir(pageData);var content = pageData;//獲取到網頁內容var hrefs=getAHref(content);//獲取鏈接});});轉載自:http://www.9958.pw/post/nodejs_get_html_a
轉載于:https://my.oschina.net/u/1179286/blog/651057
總結
以上是生活随笔為你收集整理的node.js用get方式获取网页中的链接的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nodejs下的ES6兼容性与性能分析
- 下一篇: Unable to execute de