搜尋
首頁後端開發Python教學python爬蟲需要安裝什麼

python爬蟲需要安裝什麼

Jul 05, 2019 am 10:28 AM
python

 python爬蟲需要安裝什麼

世界上80%的爬蟲是基於Python開發的,學好爬蟲技能,可為後續的大數據分析、挖掘、機器學習等提供重要的資料來源。

python爬蟲需要安裝相關庫:

python爬蟲涉及的庫:

請求庫,解析庫,存儲庫,工具庫

1. 請求庫:urllib/re/requests

(1) urllib/re是python預設自帶的函式庫,可以透過以下指令進行驗證:

#沒有報錯訊息輸出,表示環境正常

(2) requests安裝

2.1 開啟CMD,輸入

pip3 install requests

2.2 等待安裝後,驗證

(3) selenium安裝(驅動瀏覽器進行網站存取行為)

3.1 開啟CMD,輸入

pip3 install selenium

3.2 安裝chromedriver

網址:https://npm.taobao.org/

把下載完成後的壓縮套件解壓縮,把exe放到D:\Python3.6.0\Scripts\

#這個路徑只要在PATH變數就可以

3.3 等待安裝完成後,驗證

回車後彈出chrome瀏覽器介面

3.4 安裝其他瀏覽器

無介面瀏覽器phantomjs

下載網址:http://phantomjs.org/

下載完成後解壓縮,把整個目錄放到D:\Python3.6.0\Scripts\,把bin目錄的路徑加入PATH變數

驗證:

開啟CMD

phantomjs
console.log('phantomjs')

CTRL+C

python
from selenium import webdriver
driver = webdriver.PhantomJS()
dirver.get('http://www.baidu.com')
driver.page_source

2. 解析函式庫:

2.1 lxml (XPATH)

開啟CMD

pip3 install lxml

或從https://pypi.python.org下載,例如,lxml-4.1.1-cp36- cp36m-win_amd64.whl (md5) ,先下載whl檔案

pip3 install 文件名.whl

2.2 beautifulsoup

#開啟CMD,需要先安裝好lxml

pip3 install beautifulsoup4

驗證

python
from bs4 import BeautifulSoup
soup = BeautifulSoup(&#39;<html></html>&#39;,&#39;lxml&#39;)

#

pip3 install pyquery

# #2.3 pyquery(類似jquery語法)

開啟CMD

python
from pyquery import PyQuery as pq
doc = pq(&#39;<html>hi</html>&#39;)
result = doc(&#39;html&#39;).text()
result

驗證安裝結果

pip3 install pymysql

3. 儲存庫

3.1 pymysql(操作MySQL,關係型資料庫)

#安裝:

pip3 install pymongo

安裝後測試:

 

3.2 pymongo(操作MongoDB,key-value)

安裝

python
import pymongo
client = pymongo.MongoClient(&#39;localhost&#39;)
db = client[&#39;testdb&#39;]
db[&#39;table&#39;].insert({&#39;name&#39;:&#39;bob&#39;})
db[&#39;table&#39;].find_one({&#39;name&#39;:&#39;bob&#39;})

驗證

#

pip3 install redis

 

3.3 redis(分散式爬蟲,維護爬取佇列)

安裝:

pip3 install flask

驗證:

4.工具庫

4.1 flask(WEB庫)###
pip3 install django
############ 4.2 Django(分散式爬蟲維護系統)###
pip3 install jupyter
#### 4.3 jupyter(執行在網頁端的記事本,支援markdown,可以在網頁上執行程式碼)###
jupyter notebook
### 驗證:######開啟CMD###rrreee###之後就可以在網頁直接建立記事本,程式碼區塊和Markdown區塊,支援列印######【相關推薦】#######1. ###python爬蟲庫以及相關利器#########2. ###python爬蟲入門教學#######

以上是python爬蟲需要安裝什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
列表和陣列之間的選擇如何影響涉及大型數據集的Python應用程序的整體性能?列表和陣列之間的選擇如何影響涉及大型數據集的Python應用程序的整體性能?May 03, 2025 am 12:11 AM

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

說明如何將內存分配給Python中的列表與數組。說明如何將內存分配給Python中的列表與數組。May 03, 2025 am 12:10 AM

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

您如何在Python數組中指定元素的數據類型?您如何在Python數組中指定元素的數據類型?May 03, 2025 am 12:06 AM

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。

什麼是Numpy,為什麼對於Python中的數值計算很重要?什麼是Numpy,為什麼對於Python中的數值計算很重要?May 03, 2025 am 12:03 AM

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

討論'連續內存分配”的概念及其對數組的重要性。討論'連續內存分配”的概念及其對數組的重要性。May 03, 2025 am 12:01 AM

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

您如何切成python列表?您如何切成python列表?May 02, 2025 am 12:14 AM

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

在Numpy陣列上可以執行哪些常見操作?在Numpy陣列上可以執行哪些常見操作?May 02, 2025 am 12:09 AM

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Python的數據分析中如何使用陣列?Python的數據分析中如何使用陣列?May 02, 2025 am 12:09 AM

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用