golang?使用chromedp獲取頁面請(qǐng)求日志network
更新時(shí)間:2023年11月12日 11:57:35 作者:李淵橋
這篇文章主要為大家介紹了golang?使用chromedp獲取頁面請(qǐng)求日志network方法實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
golang 使用chromedp獲取頁面請(qǐng)求日志network
package main import ( "context" "io/ioutil" "log" "os" "strings" "time" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" ) func main() { dir, err := ioutil.TempDir("", "chromedp-example") if err != nil { panic(err) } defer os.RemoveAll(dir) opts := append(chromedp.DefaultExecAllocatorOptions[:], chromedp.DisableGPU, chromedp.NoDefaultBrowserCheck, chromedp.Flag("headless", false), chromedp.Flag("ignore-certificate-errors", true), chromedp.Flag("window-size", "50,400"), chromedp.UserDataDir(dir), ) allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...) defer cancel() // also set up a custom logger taskCtx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf)) defer cancel() // create a timeout taskCtx, cancel = context.WithTimeout(taskCtx, 10*time.Second) defer cancel() // ensure that the browser process is started if err := chromedp.Run(taskCtx); err != nil { panic(err) } // listen network event listenForNetworkEvent(taskCtx) chromedp.Run(taskCtx, network.Enable(), chromedp.Navigate(`https://www.iqiyi.com/v_19rsbimvyo.html`), chromedp.WaitVisible(`body`, chromedp.BySearch), ) } //監(jiān)聽 func listenForNetworkEvent(ctx context.Context) { chromedp.ListenTarget(ctx, func(ev interface{}) { switch ev := ev.(type) { case *network.EventResponseReceived: resp := ev.Response if len(resp.Headers) != 0 { // log.Printf("received headers: %s", resp.Headers) if strings.Index(resp.URL, ".ts") != -1 { log.Printf("received headers: %s", resp.URL) } } } // other needed network Event }) }
服務(wù)器部署
centos安裝 需要是64位系統(tǒng)
//安裝chrome-headless 沒有界面的瀏覽器 需要root權(quán)限 curl https://intoli.com/install-google-chrome.sh | bash 安裝 ffmpeg http://ffmpeg.org/download.html 下載地址 wget http://www.ffmpeg.org/releases/ffmpeg-3.4.1.tar.bz2 tar -xjvf ffmpeg-3.4.1.tar.bz2 cd ffmpeg-3.4.1 ./configure make && make install
以上就是golang 使用chromedp獲取頁面請(qǐng)求日志network的詳細(xì)內(nèi)容,更多關(guān)于go chromedp獲取志network的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Golang操作MySql數(shù)據(jù)庫的完整步驟記錄
這篇文章主要給大家介紹了關(guān)于Golang操作MySql數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Go語言fmt.Sprintf格式化輸出的語法與實(shí)例
Go 可以使用 fmt.Sprintf 來格式化字符串,下面這篇文章主要給大家介紹了關(guān)于Go語言fmt.Sprintf格式化輸出的語法與實(shí)例,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07一文帶你掌握Go語言I/O操作中的io.Reader和io.Writer
在?Go?語言中,io.Reader?和?io.Writer?是兩個(gè)非常重要的接口,它們?cè)谠S多標(biāo)準(zhǔn)庫中都扮演著關(guān)鍵角色,下面就跟隨小編一起學(xué)習(xí)一下它們的使用吧2025-01-01Go?interface?接口的最佳實(shí)踐經(jīng)驗(yàn)分享
go?的接口在go的編程里面用的十分頻繁,尤其是空接口的使用,因?yàn)橛辛私涌?,才使得Go語言變得異常的強(qiáng)大,今天給大家介紹下Go?interface?接口的最佳實(shí)踐經(jīng)驗(yàn)分享,感興趣的朋友一起看看吧2022-04-04Golang Gorm實(shí)現(xiàn)自定義多態(tài)模型關(guān)聯(lián)查詢
GORM 是一個(gè)流行的開源 ORM (Object-Relational Mapping) 庫,專為 Go 語言設(shè)計(jì),它簡(jiǎn)化了與 SQL 數(shù)據(jù)庫的交互,GORM 封裝了數(shù)據(jù)庫操作,使得開發(fā)者能夠通過簡(jiǎn)單的鏈?zhǔn)秸{(diào)用來執(zhí)行 CRUD,本文給大家介紹了Golang Gorm實(shí)現(xiàn)自定義多態(tài)模型關(guān)聯(lián)查詢,需要的朋友可以參考下2024-11-11golang如何設(shè)置Header Content-type
這篇文章主要介紹了golang如何設(shè)置Header Content-type問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01