golang?使用chromedp獲取頁(yè)面請(qǐng)求日志network
golang 使用chromedp獲取頁(yè)面請(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)聽(tīng)
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 沒(méi)有界面的瀏覽器 需要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獲取頁(yè)面請(qǐng)求日志network的詳細(xì)內(nèi)容,更多關(guān)于go chromedp獲取志network的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
golang實(shí)現(xiàn)對(duì)docker容器心跳監(jiān)控功能
這篇文章主要介紹了golang實(shí)現(xiàn)對(duì)docker容器心跳監(jiān)控功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
Go語(yǔ)言實(shí)現(xiàn)一個(gè)Http Server框架(二) Server的抽象
上一篇文章對(duì)http庫(kù)的基本使用做了說(shuō)明,這篇文章主要介紹了如何實(shí)現(xiàn)一個(gè)簡(jiǎn)單地httpServer,文中代碼示例非常詳細(xì),感興趣的朋友可以參考下2023-04-04
Go語(yǔ)言?xún)?nèi)建函數(shù)len的使用
Go語(yǔ)言中的len函數(shù)是一個(gè)內(nèi)建函數(shù),用于獲取數(shù)組、切片、字符串、映射和通道等數(shù)據(jù)類(lèi)型的長(zhǎng)度或大小,本文介紹了len函數(shù)在不同數(shù)據(jù)類(lèi)型中的使用場(chǎng)景和特點(diǎn),感興趣的可以了解一下2024-10-10
Golang中字符串(string)與字節(jié)數(shù)組([]byte)一行代碼互轉(zhuǎn)實(shí)例
golang語(yǔ)言本身就是c的工具集,開(kāi)發(fā)c的程序用到的大部分結(jié)構(gòu)體,內(nèi)存管理,攜程等,golang基本都有,下面這篇文章主要給大家介紹了關(guān)于Golang中字符串(string)與字節(jié)數(shù)組([]byte)一行代碼互轉(zhuǎn)的相關(guān)資料,需要的朋友可以參考下2022-09-09
Go語(yǔ)言實(shí)現(xiàn)統(tǒng)計(jì)字符串中每個(gè)字符出現(xiàn)的次數(shù)
這篇文章主要為大家詳細(xì)介紹了如何使用Go語(yǔ)言開(kāi)發(fā)一個(gè)簡(jiǎn)易頻率分析器,實(shí)現(xiàn)統(tǒng)計(jì)字符串中每個(gè)字符出現(xiàn)的次數(shù),感興趣的小伙伴可以了解一下2025-07-07

