Python crawler crawls Baidu images and keeps them locally

Python crawler crawls Baidu images and keeps them locally

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from bs4 import BeautifulSoup

# 配置ChromeDriver路径
#driver_path = 'ChromeDriver路径'
driver=webdriver.Chrome()
# 创建Chrome浏览器实例
#driver = webdriver.Chrome(executable_path=driver_path)

# 打开百度图片网页
driver.get('https://image.baidu.com/')

# 定位搜索框并输入关键词
search_box = driver.find_element(By.XPATH,"//input[@id='kw']")
search_box.send_keys("西瓜")  # 替换为你想搜索的关键词

# 定位搜索按钮并点击
search_button = driver.find_element(By.XPATH,"//input[@class='s_ne

Guess you like

Origin blog.csdn.net/m0_68165821/article/details/131485908