node 簡單的爬蟲案例

2022-08-23 12:03:12 字數 1021 閱讀 9863

cherrio模組

安裝

cnpm install cherrio
使用方法
const cheerio = require('cheerio')

const $ = cheerio.load('')

$('h2.title').text('hello there!')

$('h2').addclass('welcome')

$.html()

//=>

request模組
var request = require('request');

request('', function (error, response, body) );

爬蟲系統 request cheerio

爬取乙個**的內容資訊

分析內容

簡單的爬蟲

//發起服務端請求 請求乙個網頁 

const request = require('request')

const fs= require('fs')

const path= require('path')

const cheerio = require('cheerio')

let url =''

request(url,(err,response,body)=>else

})const $ = cheerio.load(body)

let imgs =

// 用正則判斷陣列中的路徑是否存在https

$('img').each((index, ele) => /, 'https://') //正則判斷

}imgs.push(src)

})for (let index = 0; index < imgs.length; index++) .png`)) //用下標命名,要建好img資料夾

};}})

Node 簡單爬蟲

以爬慕課網hadoop高階課程為例,用node寫乙個簡單的爬蟲 先抓取這個 的原始碼 然後分析這個頁面的dom,如圖 每大章節都被乙個chapter包圍,抓取下來就是乙個陣列,對每個item,這張的大標題在strong裡面,每章的小章節在video標籤裡,然後小標題就是j media item的te...

node的簡單爬蟲

最近在學node,這裡簡單記錄一下。首先是在linux的環境下,關於node的安裝教程 我看的教程裡面還用來express框架 鍵入 npm install express registry 來安裝 這樣基本的環境就弄好了,裝好以後來建立專案,過程如下 1.隨便建乙個資料夾,比如說是lesson3 ...

scrapy爬蟲簡單案例

進入cmd命令列,切到d盤 cmd d 建立article資料夾 mkdir articlescrapy startproject articlescrapy genspider xinwen www.hbskzy.cn 命令後面加爬蟲名和網域名稱 不能和專案名同名 items檔案 define h...