最簡單的方法解決安裝bs4的lxml解析器pip install lxml安裝報錯失敗問題

最近使用爬蟲需要用到bs4,無論是框架scrapy,還是requests請求後解析。都需要使用html解析庫。

當然正則是可以代替一部分搜索。html解析是必不可少的。

網上推薦 lxml的比較多,優點:穩定,高效

bs4文檔也是非常推薦使用

我電腦上面共存python2/3環境 pip3是python3的安裝第三庫

我在安裝的時候遇到安裝卡死或者報錯的問題,看了網上教程五花八門。

我是嘗試了安裝離線包的方法,也可以成功安裝的。

 

通過以下網址下載自己對於的whl安裝包。

https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

找到需要下載的包名

點擊跳到

 

下載後使用管理員身份打開cmd.exe。注意必須需要管理員,否則容易會權限問題導致安裝失敗

管理員打開會有administrator的標識

命令:cd 文件保存的路徑,

cd到文件目錄使用pip3 install 文件全名回車即可

使用pip3 list命令看是否安裝成功

 

from bs4 import BeautifulSoup

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""

soup = BeautifulSoup(html_doc, 'lxml')

print(soup)

執行結果

執行代碼正常能被解析,安裝成功。

 

 

版權聲明:本文爲博主原創文章,未經博主允許不得轉載。https://my.csdn.net/pangzhaowen 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章