使用编辑软件:anaconda中的Jupyter 和 vscode 编辑
Python版本:anaconda自带Python 和Python3.7.5
代码如下:
import requests
from lxml import etree
url = 'https://www.zhipin.com/'
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'}
r = requests.get(url,headers = header)
r.encoding ='utf8'
selector = etree.HTML(r.text)
selector.cssselect("#header > div > div.nav > ul > li")
报错信息:
Jupyter运行:
pip install cssselect 安装出现以下提示
conda install cssselect安装提示