欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > Python 使用selenium 4.25 进行爬虫(1)

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

2024/10/25 18:31:00 来源:https://blog.csdn.net/datouniao1/article/details/142553517  浏览:    关键词:Python 使用selenium 4.25 进行爬虫(1)

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

执行结果:

希望对你有所帮助

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com