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()  # 关闭浏览器

执行结果:

希望对你有所帮助

相关推荐
xurileidian2 小时前
第 24 篇 · 边玩边学Python · while 与死循环怎么退
服务器·前端·python
有个傻瓜2 小时前
工具调用参数每次都差一截:finish_reason=length 输出预算截断的排错复盘与四种分诊实测
python·故障排查·ai agent·大模型应用开发·function calling
zhanghongyi_cpp3 小时前
第5章 学习自测
python·学习
打工仔折腾 AI4 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
IvanCodes5 小时前
LangChain(15):LangSmith 应用评估与回归测试
python·langchain·agent
炸薯条!6 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
jason_renyu7 小时前
Playwright 入门与实操:从安装、定位、断言到自动发博客,把浏览器自动化讲明白
运维·python·自动化·前端开发·浏览器自动化·playwright·e2e测试
维克兜率天7 小时前
【维克】布林带:通道类指标的“量化基石“
人工智能·python·算法
向科→向总工→空间动态计系统8 小时前
机器人大脑系统
开发语言·人工智能·python·机器人
染指11108 小时前
194.DeepAgents-在DeepAgents中使用自定义沙盒环境OpenSandBox
网络·人工智能·python·langchain·deepagents