from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless=new') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') mobile_emulation = { "deviceMetrics": { "width": 720, "height": 1280, "pixelRatio": 1 }, "userAgent": "Mozilla/5.0 (Linux; Android 12; Pixel 5 XL) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Mobile Safari/537.36" } chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) browser = webdriver.Chrome(options=chrome_options) browser.get('https://www.baidu.com/') print(browser.title) browser.get_screenshot_as_file("capture.png") browser.close()
还可跟页面交互