golang?使用chromedp獲取頁面請求日志network
更新時間:2023年11月12日 11:57:35 作者:李淵橋
這篇文章主要為大家介紹了golang?使用chromedp獲取頁面請求日志network方法實例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
golang 使用chromedp獲取頁面請求日志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獲取頁面請求日志network的詳細內(nèi)容,更多關(guān)于go chromedp獲取志network的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Golang操作MySql數(shù)據(jù)庫的完整步驟記錄
這篇文章主要給大家介紹了關(guān)于Golang操作MySql數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-11-11一文帶你掌握Go語言I/O操作中的io.Reader和io.Writer
在?Go?語言中,io.Reader?和?io.Writer?是兩個非常重要的接口,它們在許多標準庫中都扮演著關(guān)鍵角色,下面就跟隨小編一起學習一下它們的使用吧2025-01-01Go?interface?接口的最佳實踐經(jīng)驗分享
go?的接口在go的編程里面用的十分頻繁,尤其是空接口的使用,因為有了接口,才使得Go語言變得異常的強大,今天給大家介紹下Go?interface?接口的最佳實踐經(jīng)驗分享,感興趣的朋友一起看看吧2022-04-04Golang Gorm實現(xiàn)自定義多態(tài)模型關(guān)聯(lián)查詢
GORM 是一個流行的開源 ORM (Object-Relational Mapping) 庫,專為 Go 語言設(shè)計,它簡化了與 SQL 數(shù)據(jù)庫的交互,GORM 封裝了數(shù)據(jù)庫操作,使得開發(fā)者能夠通過簡單的鏈式調(diào)用來執(zhí)行 CRUD,本文給大家介紹了Golang Gorm實現(xiàn)自定義多態(tài)模型關(guān)聯(lián)查詢,需要的朋友可以參考下2024-11-11golang如何設(shè)置Header Content-type
這篇文章主要介紹了golang如何設(shè)置Header Content-type問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01