Python爬蟲(chóng)進(jìn)階之Beautiful Soup庫(kù)詳解
一、Beautiful Soup庫(kù)簡(jiǎn)介
BeautifulSoup4 是一個(gè) HTML/XML 的解析器,主要的功能是解析和提取 HTML/XML 的數(shù)據(jù)。和 lxml 庫(kù)一樣。
lxml 只會(huì)局部遍歷,而 BeautifulSoup4 是基于 HTML DOM 的,會(huì)加載整個(gè)文檔,解析 整個(gè) DOM 樹(shù),因此內(nèi)存開(kāi)銷(xiāo)比較大,性能比較低。
BeautifulSoup4 用來(lái)解析 HTML 比較簡(jiǎn)單,API 使用非常人性化,支持 CSS 選擇器,是 Python 標(biāo)準(zhǔn)庫(kù)中的 HTML 解析器,也支持 lxml 解析器。
二、Beautiful Soup庫(kù)安裝
目前,Beautiful Soup 的最新版本是 4.x 版本,之前的版本已經(jīng)停止開(kāi)發(fā),這里推薦使用 pip 來(lái)安裝,安裝命令如下:
pip install beautifulsoup4
查看 Beautiful Soup 安裝是否成功
from bs4 import BeautifulSoup soup = BeautifulSoup('<p>Hello</p>','html.parser') print(soup.p.string)
注意:
□ 這里雖然安裝的是 beautifulsoup4 這個(gè)包,但是引入的時(shí)候卻是 bs4,因?yàn)檫@個(gè)包源 代碼本身的庫(kù)文件名稱就是bs4,所以安裝完成后,這個(gè)庫(kù)文件就被移入到本機(jī) Python3 的 lib 庫(kù)里,識(shí)別到的庫(kù)文件就叫作 bs4。
□ 因此,包本身的名稱和我們使用時(shí)導(dǎo)入包名稱并不一定是一致的。
三、Beautiful Soup 庫(kù)解析器
Beautiful Soup 在解析時(shí)實(shí)際上依賴解析器,它除了支持 Python 標(biāo)準(zhǔn)庫(kù)中的 HTML 解析器外,還支持一些第三方解析器(比如 lxml)。下表列出了 Beautiful Soup 支持的解析器。
初始化 BeautifulSoup 使用 lxml,把第二個(gè)參數(shù)改為 lxml
from bs4 import BeautifulSoup bs = BeautifulSoup('<p>Python</p>','lxml') print(bs.p.string)
四、Beautiful Soup庫(kù)基本用法
獲取 title 節(jié)點(diǎn),查看它的類(lèi)型
from bs4 import BeautifulSoup html = ''' <html><head><title>The Dormouse's story</title></head> <body> <p class="title" name="dromouse"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"><!-- Elsie --></a>, <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> </body> </html> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') print(soup.prettify()) print(soup.title.string)
執(zhí)行結(jié)果如下所示:
The Dormouse's story
- 上述示例首先聲明變量 html,它是一個(gè) HTML 字符串。接著將它當(dāng)作第一個(gè)參數(shù)傳給 BeautifulSoup 對(duì)象,該對(duì)象的第二個(gè)參數(shù)為解析器的類(lèi)型(這里使用 lxml),此時(shí)就完成了 BeaufulSoup 對(duì)象的初始化。
- 接著調(diào)用 soup 的各個(gè)方法和屬性解析這串 HTML 代碼了。
- 調(diào)用 prettify()方法。可以把要解析的字符串以標(biāo)準(zhǔn)的縮進(jìn)格式輸出。這里需要注意的是, 輸出結(jié)果里面包含 body 和 html 節(jié)點(diǎn),也就是說(shuō)對(duì)于不標(biāo)準(zhǔn)的 HTML 字符串 BeautifulSoup, 可以自動(dòng)更正格式。
- 調(diào)用 soup.title.string,輸出 HTML 中 title 節(jié)點(diǎn)的文本內(nèi)容。所以,soup.title 可以選出 HTML 中的 title 節(jié)點(diǎn),再調(diào)用 string 屬性就可以得到里面的文本了。
選擇元素
# 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取head標(biāo)簽 print(soup.head) # 獲取p標(biāo)簽 print(soup.p)
運(yùn)行結(jié)果:
<head><title>The Dormouse's story</title></head>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
- 從上述示例運(yùn)行結(jié)果可以看到,獲取 head 節(jié)點(diǎn)的結(jié)果是節(jié)點(diǎn)加其內(nèi)部的所有內(nèi)容。
- 最后,選擇了 p 節(jié)點(diǎn)。不過(guò)這次情況比較特殊,我們發(fā)現(xiàn)結(jié)果是第一個(gè) p 節(jié)點(diǎn)的內(nèi)容,后面的幾個(gè) p 節(jié)點(diǎn)并沒(méi)有選到。也就是說(shuō),當(dāng)有多個(gè)節(jié)點(diǎn)時(shí),這種選擇方式只會(huì)選擇到第一個(gè)匹配的節(jié)點(diǎn),其他的后面節(jié)點(diǎn)都會(huì)忽略。
調(diào)用 name 屬性獲取節(jié)點(diǎn)的名稱
# 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 調(diào)用 name 屬性獲取節(jié)點(diǎn)的名稱 print(soup.title.name)
運(yùn)行結(jié)果:
title
調(diào)用 attrs 獲取所有屬性
# 調(diào)用 attrs 獲取所有屬性 print(soup.p.attrs) print(soup.p.attrs['name'])
運(yùn)行結(jié)果:
{'class': ['title'], 'name': 'dromouse'}
dromouse
從上述運(yùn)行結(jié)果可以看到,attrs 的返回結(jié)果是字典形式,它把選擇節(jié)點(diǎn)的所有屬性和屬性值組合成一個(gè)字典。
如果要獲取 name 屬性,就相當(dāng)于從字典中獲取某個(gè)鍵值,只需要用中括號(hào)加屬性名就可以了。例如,要獲取 name 屬性,就可以通過(guò) attrs[‘name'] 來(lái)得到。
簡(jiǎn)單獲取屬性的方式
print(soup.p['name']) print(soup.p['class'])
這里需要注意的是,獲取屬性有的返回結(jié)果是字符串,有的返回結(jié)果是字符串組成的列表。
比如,name 屬性的值是唯一的,返回的結(jié)果就是單個(gè)字符串。而對(duì)于 class,一個(gè)節(jié)點(diǎn)元素可能有多個(gè) class,所以返回的是列表。
調(diào)用 string 屬性獲取節(jié)點(diǎn)元素包含的文本內(nèi)容
print('調(diào)用 string 屬性獲取節(jié)點(diǎn)元素包含的文本內(nèi)容') print(soup.p.string)
嵌套選擇
print('嵌套選擇') print(soup.head.title) # 獲取title的類(lèi)型 print(type(soup.head.title)) # 獲取標(biāo)簽內(nèi)容 print(soup.head.title.string)
運(yùn)行結(jié)果:
<title>The Dormouse's story</title>
<class 'bs4.element.Tag'>
The Dormouse's story
從上述示例運(yùn)行結(jié)果可以看到,調(diào)用 head 之后再次調(diào)用 title 可以選擇 title 節(jié)點(diǎn)元素。 輸出了它的類(lèi)型可以看到,它仍然是 bs4.element.Tag 類(lèi)型。也就是說(shuō),我們?cè)?Tag 類(lèi)型的基礎(chǔ)上再次選擇得到的依然還是 Tag 類(lèi)型,每次返回的結(jié)果都相同。
調(diào)用 children 屬性,獲取它的直接子節(jié)點(diǎn)
from bs4 import BeautifulSoup html = ''' <html> <head> <title>The Dormouse's story</title> </head> <body> <p class="story"> Once upon a time there were three little sisters; and their names were <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"> <span>Elsie</span> </a> <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link3">Tillie</a> and they lived at the bottom of a well. </p> <p class="story">...</p> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取孩子結(jié)點(diǎn) print(soup.p.children) # 遍歷孩子結(jié)點(diǎn) # 將列表中元素與下標(biāo)枚舉為元組 # 獲取p標(biāo)簽下的孩子標(biāo)簽 for i, child in enumerate(soup.p.children): print(i, child)
執(zhí)行結(jié)果:
<list_iterator object at 0x0CACF448>
0 Once upon a time there were three little sisters; and their names were
1 <a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
2
3 <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>
4 and
5 <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>
6 and they lived at the bottom of a well.
從上述示例運(yùn)行結(jié)果可以看到,調(diào)用 children 屬性,返回結(jié)果是生成器類(lèi)型。用 for 循環(huán)輸出相應(yīng)的內(nèi)容。
調(diào)用 parent 屬性,獲取某個(gè)節(jié)點(diǎn)元素的父節(jié)點(diǎn)
from bs4 import BeautifulSoup html = ''' <html> <head> <title>The Dormouse's story</title> </head> <body><p class="story"> Once upon a time there were three little sisters; and their names were <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"> <span>Elsie</span> </a> </p> <p class="story">...</p> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取父結(jié)點(diǎn) print(soup.a.parent)
運(yùn)行結(jié)果:
<p class="story"> Once upon a time there were three little sisters; and their names were
<a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
</p>
從上述示例運(yùn)行結(jié)果可以看到,我們選擇的是第一個(gè) a 節(jié)點(diǎn)的父節(jié)點(diǎn)元素,它的父節(jié)點(diǎn) 是 p 節(jié)點(diǎn),輸出結(jié)果便是 p 節(jié)點(diǎn)及其內(nèi)部的內(nèi)容。 需要注意的是,這里輸出的僅僅是 a 節(jié)點(diǎn)的直接父節(jié)點(diǎn),而沒(méi)有再向外尋找父節(jié)點(diǎn)的祖 先節(jié)點(diǎn)。如果想獲取所有的祖先節(jié)點(diǎn),可以調(diào)用 parents 屬性。
調(diào)用 parents 屬性,獲取某個(gè)節(jié)點(diǎn)元素的祖先節(jié)點(diǎn)
from bs4 import BeautifulSoup html = ''' <html> <body><p class="story"> <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"> <span>Elsie</span> </a> </p> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取父結(jié)點(diǎn) print(type(soup.a.parents)) # 獲取類(lèi)型 print(list(enumerate(soup.a.parents)))
運(yùn)行結(jié)果:
[(0, <p class="story">
<a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
</p>), (1, <body><p class="story">
<a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
</p>
</body>), (2, <html>
<body><p class="story">
<a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
</p>
</body></html>), (3, <html>
<body><p class="story">
<a class="sister" href="http://example.com/elsie" id="link1">
<span>Elsie</span>
</a>
</p>
</body></html>)]
調(diào)用 next_sibling 和 previous_sibling 分別獲取節(jié)點(diǎn)的下一個(gè)和上一個(gè)兄弟元素
from bs4 import BeautifulSoup html = ''' <html> <body> <p class="story"> Once upon a time there were three little sisters; and their names were <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"> <span>Elsie</span> </a> Hello <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and <a rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link3">Tillie</a> and they lived at the bottom of a well. </p> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取下一個(gè)結(jié)點(diǎn)的屬性 print('Next Sibling', soup.a.next_sibling) print('Previous Sibling', soup.a.previous_sibling)
運(yùn)行結(jié)果:
Next Sibling Hello
Previous Sibling Once upon a time there were three little sisters; and their names were
五、方法選擇器
上面所講的選擇方法都是通過(guò)屬性來(lái)選擇的,這種方法非常快,但是如果進(jìn)行比較復(fù)雜的選擇的話,它就比較煩瑣,不夠靈活了。
Beautiful Soup 還提供了一些查詢方法,例如:find_all()和 find()等。
find_all 是查詢所有符合條件的元素。給它傳入一些屬性或文本,就可以得到符合條件的元素,它的功能十分強(qiáng)大。
語(yǔ)法格式如下:
find_all(name , attrs , recursive , text , **kwargs)
find_all 方法傳入 name 參數(shù),根據(jù)節(jié)點(diǎn)名來(lái)查詢?cè)?/p>
from bs4 import BeautifulSoup html = ''' <div class="panel"> <div class="panel-heading"> <h4>Hello</h4> </div> <div class="panel-body"> <ul class="list" id="list-1"> <li class="element">Foo</li> <li class="element">Bar</li> <li class="element">Jay</li> </ul> <ul class="list list-small" id="list-2"> <li class="element">Foo</li> <li class="element">Bar</li> </ul> </div> </div> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') for ul in soup.find_all(name='ul'): print(ul.find_all(name='li')) for li in ul.find_all(name='li'): print(li.string)
結(jié)果如下:
[<li class="element">Foo</li>, <li class="element">Bar</li>, <li class="element">Jay</li>]
Foo
Bar
Jay
[<li class="element">Foo</li>, <li class="element">Bar</li>]
Foo
Bar
從上述示例可以看到,調(diào)用 find_all()方法,name 參數(shù)值為 ul。返回結(jié)果是查詢到的所有 ul 節(jié)點(diǎn)列表類(lèi)型,長(zhǎng)度為 2,每個(gè)元素依然都是 bs4.element.Tag 類(lèi)型。因?yàn)槎际?Tag 類(lèi)型, 所以依然可以進(jìn)行嵌套查詢。再繼續(xù)查詢其內(nèi)部的 li 節(jié)點(diǎn),返回結(jié)果是 li 節(jié)點(diǎn)列表類(lèi)型, 遍歷列表中的每個(gè) li,獲取它的文本。
find_all 方法傳入 attrs 參數(shù),根據(jù)屬性來(lái)查詢
from bs4 import BeautifulSoup html = ''' <div class="panel"> <div class="panel-heading"> <h4>Hello</h4> </div> <div class="panel-body"> <ul class="list" id="list-1" name="elements"> <li class="element">Foo</li> <li class="element">Bar</li> <li class="element">Jay</li> </ul> <ul class="list list-small" id="list-2"> <li class="element">Foo</li> <li class="element">Bar</li> </ul> </div> </div> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') print(soup.find_all(attrs={'id': 'list-1'})) print(soup.find_all(attrs={'name': 'elements'}))
結(jié)果如下:
[<ul class="list" id="list-1" name="elements">
<li class="element">Foo</li>
<li class="element">Bar</li>
<li class="element">Jay</li>
</ul>]
[<ul class="list" id="list-1" name="elements">
<li class="element">Foo</li>
<li class="element">Bar</li>
<li class="element">Jay</li>
</ul>]
從上述示例可以看到,傳入 attrs 參數(shù),參數(shù)的類(lèi)型是字典類(lèi)型。比如,要查詢 id 為 list-1 的節(jié)點(diǎn),可以傳入 attrs={‘id': ‘list-1'}的查詢條件,得到的結(jié)果是列表形式,包含的內(nèi)容就是符合 id 為 list-1 的所有節(jié)點(diǎn)。符合條件的元素個(gè)數(shù)是 1,長(zhǎng)度為 1 的列表。
對(duì)于一些常用的屬性,比如 id 和 class 等,可以不用 attrs 來(lái)傳遞。比如,要查詢 id 為 list-1 的節(jié)點(diǎn) ,可以直接傳入 id 這個(gè)參數(shù)。
示例如下:
print(soup.find_all(id='list-1')) print(soup.find_all(class_='element'))
上述示例直接傳入 id='list-1',就可以查詢 id 為 list-1 的節(jié)點(diǎn)元素了。而對(duì)于 class 來(lái) 說(shuō),由于 class 在 Python 里是一個(gè)關(guān)鍵字,所以后面需要加一個(gè)下劃線,即 class_='element', 返回的結(jié)果依然還是 Tag 組成的列表。
find_all 方法根據(jù)文本來(lái)查詢
find_all 方法傳入 text 參數(shù)可用來(lái)匹配節(jié)點(diǎn)的文本,傳入的形式可以是字符串,可以是正則表達(dá)式對(duì)象。
from bs4 import BeautifulSoup import re html = ''' <div class="panel"> <div class="panel-body"> <a>Hello, this is a link</a> <a>Hello, this is a link, too</a> </div> </div> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') print(soup.find_all(text=re.compile('link')))
運(yùn)行結(jié)果
['Hello, this is a link', 'Hello, this is a link, too']
上述示例有兩個(gè) a 節(jié)點(diǎn),其內(nèi)部包含文本信息。這里在 find_all()方法中傳入 text 參數(shù), 該參數(shù)為正則表達(dá)式對(duì)象,結(jié)果返回所有匹配正則表達(dá)式的節(jié)點(diǎn)文本組成的列表。
除了 find_all()方法,還有 find()方法,不過(guò)后者返回的是單個(gè)元素,也就是第一個(gè)匹配的元素,而前者返回的是所有匹配的元素組成的列表。
find 方法查詢第一個(gè)匹配的元素
from bs4 import BeautifulSoup import re html = ''' <<div class="panel"> <div class="panel-heading"> <h4>Hello</h4> </div> <div class="panel-body"> <ul class="list" id="list-1"> <li class="element">Foo</li> <li class="element">Bar</li> <li class="element">Jay</li> </ul> <ul class="list list-small" id="list-2"> <li class="element">Foo</li> <li class="element">Bar</li> </ul> </div> </div> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取標(biāo)簽名為ul的標(biāo)簽體內(nèi)容 print(soup.find(name='ul')) # 獲取返回結(jié)果的列表 print(type(soup.find(name='ul'))) # 查找標(biāo)簽中class是'list' print(soup.find(class_='list'))
結(jié)果如下
<ul class="list" id="list-1">
<li class="element">Foo</li>
<li class="element">Bar</li>
<li class="element">Jay</li>
</ul>
<class 'bs4.element.Tag'>
<ul class="list" id="list-1">
<li class="element">Foo</li>
<li class="element">Bar</li>
<li class="element">Jay</li>
</ul>
上述示例使用 find 方法返回結(jié)果不再是列表形式,而是第一個(gè)匹配的節(jié)點(diǎn)元素,類(lèi)型依然是 Tag 類(lèi)型。
六、CSS 選擇器
Beautiful Soup 還提供了另外一種選擇器,那就是 CSS 選擇器。使用 CSS 選擇器時(shí),只 需要調(diào)用 select()方法,傳入相應(yīng)的 CSS 選擇器即可。
CSS相關(guān)知識(shí):
#element: id選擇器.
element:類(lèi)選擇器
tag tag:派生選擇器
通過(guò)依據(jù)元素在其位置的上下文關(guān)系來(lái)定義樣式,你可以使標(biāo)記更加簡(jiǎn)潔。
from bs4 import BeautifulSoup import re html = ''' <div class="panel"> <div class="panel-heading"> <h4>Hello</h4> </div> <div class="panel-body"> <ul class="list" id="list-1"> <li class="element">Foo</li> <li class="element">Bar</li> <li class="element">Jay</li> </ul> <ul class="list list-small" id="list-2"> <li class="element">Foo</li> <li class="element">Bar</li> </ul> </div> </div> ''' # 獲取bs4解析對(duì)象,使用解析器:lxml,html:解析內(nèi)容 soup = BeautifulSoup(html, 'lxml') # 獲取class=panel標(biāo)簽下panel_heading,類(lèi)選擇器 print(soup.select('.panel .panel-heading')) # 派生選擇器 print(soup.select('ul li')) # id選擇器+類(lèi)選擇器 lis = soup.select('#list-2 .element') for l in lis: print('GET TEXT', l.get_text()) print('String:', l.string)
結(jié)果如下
[<div class="panel-heading">
<h4>Hello</h4>
</div>]
[<li class="element">Foo</li>, <li class="element">Bar</li>, <li class="element">Jay</li>, <li class="element">Foo</li>, <li class="element">Bar</li>]
GET TEXT Foo
String: Foo
GET TEXT Bar
String: Bar
上述示例,用了 3 次 CSS 選擇器,返回的結(jié)果均是符合 CSS 選擇器的節(jié)點(diǎn)組成的列表。 例如,select(‘ul li')則是選擇所有 ul 節(jié)點(diǎn)下面的所有 li 節(jié)點(diǎn),結(jié)果便是所有的 li 節(jié)點(diǎn)組成的列表。要獲取文本,當(dāng)然也可以用前面所講的 string 屬性。此外,還有一個(gè)方法,那就是 get_text()。
到此這篇關(guān)于Python爬蟲(chóng)進(jìn)階之Beautiful Soup庫(kù)詳解的文章就介紹到這了,更多相關(guān)Python Beautiful Soup庫(kù)詳解內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python實(shí)戰(zhàn)快速上手BeautifulSoup庫(kù)爬取專欄標(biāo)題和地址
- python beautiful soup庫(kù)入門(mén)安裝教程
- python爬蟲(chóng)學(xué)習(xí)筆記--BeautifulSoup4庫(kù)的使用詳解
- python BeautifulSoup庫(kù)的安裝與使用
- Python爬蟲(chóng)庫(kù)BeautifulSoup的介紹與簡(jiǎn)單使用實(shí)例
- python用BeautifulSoup庫(kù)簡(jiǎn)單爬蟲(chóng)實(shí)例分析
- python3解析庫(kù)BeautifulSoup4的安裝配置與基本用法
- python3第三方爬蟲(chóng)庫(kù)BeautifulSoup4安裝教程
- Python使用Beautiful?Soup(BS4)庫(kù)解析HTML和XML
相關(guān)文章
Django csrf 驗(yàn)證問(wèn)題的實(shí)現(xiàn)
csrf是通過(guò)偽裝來(lái)自受信任用戶的請(qǐng)求來(lái)利用受信任的網(wǎng)站。這篇文章主要介紹了Django csrf 驗(yàn)證問(wèn)題的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10python實(shí)現(xiàn)電子產(chǎn)品商店
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)電子產(chǎn)品商店,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02Python使用requirements.txt和pip打包批量安裝的實(shí)現(xiàn)
本文主要介紹了Python使用requirements.txt和pip打包批量安裝的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02python random從集合中隨機(jī)選擇元素的方法
今天小編就為大家分享一篇python random從集合中隨機(jī)選擇元素的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-01-01Python實(shí)戰(zhàn)小項(xiàng)目之身份證信息校驗(yàn)
讀萬(wàn)卷書(shū)不如行萬(wàn)里路,只學(xué)書(shū)上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用Python做一個(gè)身份證信息校驗(yàn)的小項(xiàng)目,大家可以在過(guò)程中查缺補(bǔ)漏,提升水平2021-10-1030道python自動(dòng)化測(cè)試面試題與答案匯總
對(duì)于機(jī)器學(xué)習(xí)算法工程師而言,Python是不可或缺的語(yǔ)言,它的優(yōu)美與簡(jiǎn)潔令人無(wú)法自拔,下面這篇文章主要給大家介紹了關(guān)于30道python自動(dòng)化測(cè)試面試題與答案匯總的相關(guān)資料,需要的朋友可以參考下2023-03-03django開(kāi)發(fā)之settings.py中變量的全局引用詳解
當(dāng)網(wǎng)站里面的一些內(nèi)容,如郵箱,網(wǎng)站標(biāo)題,網(wǎng)站的描述,這些東西我們可以存在數(shù)據(jù)庫(kù)中也可以存放在我們的setting 文件中,這篇文章主要給大家介紹了django中settings.py變量的全局引用的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友可以參考下。2017-03-03如何基于Python和Flask編寫(xiě)Prometheus監(jiān)控
這篇文章主要介紹了如何基于Python和Flask編寫(xiě)Prometheus監(jiān)控,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11Python中ModuleNotFoundError錯(cuò)誤的問(wèn)題解決
本文主要介紹了Python中ModuleNotFoundError錯(cuò)誤的問(wèn)題解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02