先介绍一个网站——句子迷,网站上有众多网友分享的经典句子,我们将搜索我们喜欢的作者,爬取所有该作者的名句。
我们利用selenium来进行可视化的爬虫,首先要pip install selenium,然后下载谷歌chrome浏览器的驱动,选择对应的版本即可。下载后解压,将路径添加到系统环境变量中,方便使用。
首先运行get_motto.py 来获得句子,存为mottos.json 和motto.txt。mottos.json 包含‘author’,'title', ‘paragraphs'。后面读取这个json文件,随机选取一句话,显示到桌面背景上。
get_motto.py
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 19 15:39:49 2018
@author: xiaozhen
"""
import time
import re
import json
from seleniu