from selenium import webdriver
from selenium.webdriver.common.by import By
option = webdriver.ChromeOptions()
# 不打开浏览器窗口
option.add_argument("headless")
# 创建 WebDriver 对象,指明使用chrome浏览器驱动
wd = webdriver.Chrome(executable_path=r'D:\learn\environment\chromedriver_win32\chromedriver.exe',
options=option)
# 如果没有数据,则每个半秒再获取一次,直到拿到数据或总时间超过10秒
wd.implicitly_wait(10)
# 调用WebDriver 对象的get方法 可以让浏览器打开指定网址
wd.get('https://movie.douban.com/')
els = wd.find_elements(By.CSS_SELECTOR, 'body')
for e in els:
print(e.get_attribute('outerHTML'))
# 退出
wd.quit()
python爬虫样例
最新推荐文章于 2023-05-12 16:30:03 发布