1、安装selenium
在CMD输入pip install selenium即可,pip(包管理器)相关请阅读https://blog.csdn.net/u010622242/article/details/84979705
2、在py文件中写如下代码,注意代码的缩进,python对代码缩进要求很严格。
#coding:utf-8
from selenium import webdriver
self = webdriver.Chrome() #指定selenium进行自动化操作时选用谷歌浏览器
self.get('https://yuedu.baidu.com/book/list/3001?show=0') #要打开的网页
total_book = self.find_element_by_id('bd')
books = total_book.find_elements_by_class_name('book ') #找到已经定位到的div盒子里的每一个包含图书介绍的子div
for book in books: #通过for循环依次把每一本图书的内容取出来
print (book.text + '\n') #将爬取到的内容打印
self.quit() #爬取数据完成后关闭浏览器
3、下载并使用谷歌浏览器驱动chromedriver
移步https://blog.csdn.net/u010622242/article/details/84979997
4、执行py文件
在cmd中输入:python 爬取.py