windows 64位操作系統下,用 Python 抓取網頁,並用 pyQuery 解析網頁
pyQuery是jQuery在python中的實現,能夠以jQuery的語法來操作解析HTML文檔,十分方便。使用前需要安裝,easy_install pyquery即可,或者Ubuntu下
詳情參考:
http://blog.csdn.net/zhaoyl03/article/details/8631645
但是用pip命令安裝pyquey的時候,報錯了
pip install pyquery
提示需要先安裝 lxml ,於是用如下命令安裝 lxml
pip install lxml
報錯
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
查資料,知乎上找到如下解決方案:https://www.zhihu.com/question/30047496 親測有效。
1. 安裝wheel,命令行運行: pip install wheel 2.在這里下載對應的.whl文件,注意別改文件名! http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml 3. 進入.whl所在的文件夾,執行命令即可完成安裝 pip install 帶后綴的完整文件名
從上面的地址下載到適合我電腦的whl文件:lxml-3.6.4-cp27-cp27m-win_amd64.whl
然后在安裝 pyquery,成功搞定!
C:\Python27\Scripts>pip install lxml-3.6.4-cp27-cp27m-win_amd64.whl Processing c:\python27\scripts\lxml-3.6.4-cp27-cp27m-win_amd64.whl Installing collected packages: lxml Successfully installed lxml-3.6.4 C:\Python27\Scripts>pip install pyquery Collecting pyquery Using cached pyquery-1.2.17-py2.py3-none-any.whl Requirement already satisfied: lxml>=2.1 in c:\python27\lib\site-packages (from pyquery) Requirement already satisfied: cssselect>0.7.9 in c:\python27\lib\site-packages (from pyquery) Installing collected packages: pyquery Successfully installed pyquery-1.2.17