from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
url = input(“请输入你要访问的网址: “)
user_agent = ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36’
chrome_options = Options()
chrome_options.add_argument(“–log-level=3”)
chrome_options.add_argument(“–disable-logging”)
chrome_options.add_argument(“–user-data-dir=C:/selenium-profile”)
chrome_options.add_argument(“–profile-directory=Default”)
chrome_options.add_argument(f’user-agent={user_agent}’)
driver = webdriver.Chrome(options=chrome_options)
service = Service(r”C:\Windows\System32\chromedriver.exe”, log_path=”NUL”)
driver.get(url)
html_source = driver.page_source
with open(“rendered.html”, “w”, encoding=”utf-8″) as f:
f.write(html_source)
with open(“rendered.html”, “r”, encoding=”utf-8″) as f:
soup = BeautifulSoup(f, “html.parser”)
for img in (img for img in soup.find_all(“img”, src=True, placeholder=True, class_=True) if len(img.attrs) == 3):
print(img[“src”])
driver.quit()
披荊斬棘開山河路,立志中興定萬世基。