W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
這里有一些 ?Selector
? 舉例說明幾個(gè)概念。在所有情況下,我們假設(shè) ?Selector
? 用一個(gè) ?HtmlResponse
? 這樣的對(duì)象:
sel = Selector(html_response)
1、選擇全部 ?<h1>? 來自HTML響應(yīng)正文的元素,返回 ?Selector? 對(duì)象(即 ?SelectorList? 對(duì)象):
sel.xpath("http://h1")
2、提取所有文本 <h1> 元素,返回字符串列表:
sel.xpath("http://h1").getall() # this includes the h1 tag
sel.xpath("http://h1/text()").getall() # this excludes the h1 tag
3、全部迭代 <p> 標(biāo)記并打印其類屬性:
for node in sel.xpath("http://p"):
print(node.attrib['class'])
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: