查看自己google浏览器的版本
下载与之对应的google浏览器驱动
将驱动配置放到和python.exe的同级目录下,如果不知道python在哪里可以打开cmd
where python
开始自动化调用
import time
from selenium import webdriver
# 创建Chrome浏览器驱动
driver = webdriver.Chrome()
# 打开网页
url = 'https://www.zhihu.com/search?type=content&q=sport'
driver.get(url)
# 获取网页源代码
html = driver.page_source
title = driver.title
print(title)
# 阻塞3秒
time.sleep(30)
# 关闭浏览器驱动
driver.quit()
# 输出网页源代码
print(html)