Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use chromedp crawler to open a new tab in golang

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use chromedp crawler to open new tabs in golang, the editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

When using the chromedp crawler, if you click on the a tag with the attribute target= "_ blank", the context remains on the current page and you need to use another container to open the new page.

Package mainimport ("context"fmt"github.com/chromedp/cdproto/target"github.com/chromedp/chromedp"log"net/http"net/http/httptest") func main () {ctx, cancel: = chromedp.NewContext (context.Background ()) defer cancel () ch: = addNewTabListener (ctx) err: = chromedp.Run (ctx) Chromedp.Navigate ("https://music.migu.cn/v3/music/player/audio"), chromedp.SetValue (" # search_ipt "," enter the name of the song to search ", chromedp.ByID), chromedp.Click (`i [class =" iconfont cf-nav-sousuo "] `, chromedp.BySearch),) if err! = nil {log.Fatal (err)} newCtx, cancel: = chromedp.NewContext (ctx, chromedp.WithTargetID (

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 208

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report