from requests_html import HTMLSession
在输入上面这串代码之后有的时候会出现 'ModuleNotFoundError: No module named ‘requests_html’ 这样的提示,这个主要是因为我们没有安装上requests_html这个包
接下来有两种方法可以安装这个包
方法一:用pip安装
首先打开cmd,输入下面代码找出python的脚本位置:
C:\Users >python -m site --user-site
一般查出的位置文件夹是C:\Users\Username\AppData\Roaming\Python36\site-packages,之后我们把site-packages改成Scripts进入 C:\Users\Username\AppData\Roaming\Python36\Scripts这个文件夹中
,这个位置就是脚本文件夹,我们需要在这个位置中安装requests_html这个包,所以接下来输入下面的代码进入这个文件夹
C:\Users >cd C:\Users\Username\AppData\Roaming\Python36\Scripts
在这个文件夹的环境下,输入下面代码安装request_html这个安装包
C:\Users\Username\AppData\Roaming\Python36\Scripts >pip3
install requests-html
然后会有提示说安装成功
方法二:用pipenv这个环境依赖包安装requests-html这个包
如果我们没有pipenv的话,第一步应该是先安装pipenv,接下来我们要先安装pipenv
也是需要在脚本位置安装pipenv,用方法一中的方法找到scripts的位置,然后输入下面代码安装pipenv:
C:\Users\Username\AppData\Roaming\Python36\Scripts > pip install --user
pipenv
然后安装我们所需要的request-html这个包:
C:\Users\Username\AppData\Roaming\Python36\Scripts >pipenv install requests_html
然后启动包:
C:\Users\Username\AppData\Roaming\Python36\Scripts > pipenv shell
接下来就可以在脚本环境下打开 jupyter notebook使用这个requests-html这个包啦。
输入代码启动 jupyter notebook:
C:\Users\Username\AppData\Roaming\Python36\Scripts > jupyter notebook