国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語(yǔ)言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - python爬蟲(chóng)之BeautifulSoup 使用select方法詳解

python爬蟲(chóng)之BeautifulSoup 使用select方法詳解

2020-12-13 00:14古怪的一陣風(fēng) Python

本篇文章主要介紹了python爬蟲(chóng)之BeautifulSoup 使用select方法詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文介紹了python爬蟲(chóng)BeautifulSoup 使用select方法詳解 ,分享給大家。具體如下:

 
?
1
 
2
3
4
5
6
7
8
9
10
<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 href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" 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>
"""

我們?cè)趯?CSS 時(shí),標(biāo)簽名不加任何修飾,類名前加點(diǎn),id名前加 #,在這里我們也可以利用類似的方法來(lái)篩選元素,用到的方法是 soup.select(),返回類型是 list

(1)通過(guò)標(biāo)簽名查找

 
?
1
 
2
3
4
5
6
7
8
print soup.select('title')
#[<title>The Dormouse's story</title>]
 
print soup.select('a')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>, <a class="sister" href="http://example.com/lacie" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link2">Lacie</a>, <a class="sister" href="http://example.com/tillie" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link3">Tillie</a>]
 
print soup.select('b')
#[<b>The Dormouse's story</b>]

(2)通過(guò)類名查找

 
?
1
 
2
print soup.select('.sister')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>, <a class="sister" href="http://example.com/lacie" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link2">Lacie</a>, <a class="sister" href="http://example.com/tillie" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link3">Tillie</a>]

(3)通過(guò) id 名查找

 
?
1
 
2
print soup.select('#link1')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>]

(4)組合查找

組合查找即和寫 class 文件時(shí),標(biāo)簽名與類名、id名進(jìn)行的組合原理是一樣的,例如查找 p 標(biāo)簽中,id 等于 link1的內(nèi)容,二者需要用空格分開(kāi)

 
?
1
 
2
print soup.select('p #link1')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>]

直接子標(biāo)簽查找

 
?
1
 
2
print soup.select("head > title")
#[<title>The Dormouse's story</title>]

(5)屬性查找

查找時(shí)還可以加入屬性元素,屬性需要用中括號(hào)括起來(lái),注意屬性和標(biāo)簽屬于同一節(jié)點(diǎn),所以中間不能加空格,否則會(huì)無(wú)法匹配到。

 
?
1
 
2
3
4
5
print soup.select("head > title")
#[<title>The Dormouse's story</title>]
 
print soup.select('a[href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ]')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>]

同樣,屬性仍然可以與上述查找方式組合,不在同一節(jié)點(diǎn)的空格隔開(kāi),同一節(jié)點(diǎn)的不加空格

 
?
1
 
2
print soup.select('p a[href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ]')
#[<a class="sister" href="http://example.com/elsie" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1"><!-- Elsie --></a>]

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://www.cnblogs.com/yizhenfeng168/p/6979339.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩美女国产精品 | 91尤物网站网红尤物福利 | 久久精品91久久久久久再现 | 精品一区视频 | 国产成人精品一区二区 | 91久久国产综合久久91精品网站 | 北条麻妃一区二区三区在线观看 | 国产真实精品久久二三区 | 国产视频三区 | 欧美日韩在线免费观看 | 毛片首页| 国产在线a | 久久天堂视频 | 国产日韩欧美在线 | 影音先锋在线看片资源 | 精品视频第一页 | 人妖天堂狠狠ts人妖天堂狠狠 | 欧美一区永久视频免费观看 | 99精品视频在线观看 | 国产精品视频一区二区三区 | 日韩一区在线视频 | 国产免费自拍av | av免费黄色 | 国产一区二区三区在线视频 | 日本不卡在线观看 | 精品国产一区二区三区四 | 国产一级特黄aaa大片 | 日韩av片在线免费观看 | 狠狠爱综合 | 日韩av一区二区在线观看 | 久久中文字幕一区 | 免费看黄色一级视频 | 国产精品久久久久久久久久东京 | 最近中文字幕免费观看 | 日韩欧美中文在线观看 | 99综合在线 | 91免费版在线观看 | 亚洲精品久久久久999中文字幕 | 在线看的毛片 | 九九热精品视频在线观看 | 91羞羞网站|