Turn on Google Chrome remote debugging function

Google Chrome remote debugging function

First we start Chrome's remote debugging port. You need to find the installation location of Chrome. Enter it in the Chrome address bar chrome://versionto find the installation path of Chrome.

Enable remote control command

文件路径/chrome.exe --remote-debugging-port=9222

What it looks like after opening (note that you need to close other Google Chrome windows)

What it looks like after turning it on

Remember webSocketDebuggerUrlthe address at the end. This is the address of our remote link

Puppeteer

const puppeteer = require('puppeteer-core')

async function run(){
  var address = 'ws://127.0.0.1:9222/devtools/browser/6f2ae4-ff55-46e9-a50-7f89746a98e8'
  const browser = await puppeteer.connect({
  browserWSEndpoint: address,
});
  const page = await browser.newPage();
response = await page.goto('http:www.baidu.com', { waitUntil: 'load', timeout: 0 });
}
run()

The core of this code is just two lines, connecting to remote Chrome

var address = 'ws://127.0.0.1:9222/devtools/browser/6f2ae4-ff55-46e9-a50-7f89746a98e8'
  const browser = await puppeteer.connect({
  browserWSEndpoint: address,
});

During the test, you may find that more and more tabs are opened. After your crawler completes its operation, you can use await page.close()to close the current tab. This browser window can be used as long as at least one tab remains open.

selenium

chrome.exe --remote-debugging-port=9222 --user-data-dir="D:\selenium\chrome_temp"

For the -remote-debugging-port value, any open port can be specified.

For the -user-data-dir tag, specify the directory where new Chrome profiles are created. It is to ensure that launching chrome in a separate profile does not pollute your default profile.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")chrome_driver = "F:\\chromedriver.exe"driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)driver.find_element_by_id('kw').send_keys('你好')

Guess you like

Origin blog.csdn.net/xiaoyao961/article/details/132549038