python爬虫爬取百度图片并保持到本地

python爬虫爬取百度图片并保持到本地

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

你可能感兴趣的:(python学习,python,爬虫,开发语言)