Python 使用selenium 4.25 进行爬虫(1)

都说python做爬虫比较好,于是我跟着大家的脚步学习python进行爬虫,但是调试了半天,出现各种各样的问题,最终都得到实现了,下面我们来看具体的代码:

python 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service



 
# 如果你没有安装ChromeDriver,需要先下载并配置到环境变量
#driver_path = 'C://chromedriver127.exe'
driver_path = 'C://drivers/chromedriver.exe'   ## 驱动路径
print(webdriver.__version__)   ## 打印selenium的版本
service = Service(driver_path)   ## 创建Serice

# 创建一个 Chrome 浏览器实例
#driver = webdriver.Chrome(executable_path=driver_path)
chrome_options = Options()   ## 定义浏览器选项
chrome_options.add_argument("--headless")  # 无界面模式
 

driver = webdriver.Chrome(service=service,options=chrome_options)  ## 实现驱动


url = "https://www.read8686.com"
driver.get(url)  ##开始爬虫获取

content = driver.page_source  # 获取渲染后的HTML内容
 
# 做你需要的操作,例如解析HTML内容
print(content)
driver.quit()  # 关闭浏览器

执行结果:

希望对你有所帮助

相关推荐
IVEN_14 小时前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang15 小时前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮16 小时前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling16 小时前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python
AI攻城狮19 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽19 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健1 天前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞1 天前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽2 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers