from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
# It is not mandatory to specify all this, but it is strongly recommended for any web scraping software
opts = Options()
# make web scraping 'invisible'
opts.add_argument("--headless")
opts.add_argument('--no-sandbox')
user_agent = "user-agent=[Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36]"
opts.add_argument(user_agent)
# ChromeDriverManager ensures no webdriver recovery issues under any supported operating system
# If you don't like this way, use the classic webdriver with the system path
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=opts)
browser.get('chrome://version/')
element = browser.find_element(By.ID, "profile_path")
print(element.text)
1条答案
按热度按时间9njqaruj1#
只需导航到该页面并检索您正在查找元素。
我将插入一个完整的代码解释一步一步。
在我例子中,输出将是: