W3Cschool
恭喜您成為首批注冊用戶
獲得88經驗值獎勵
這里有一些 ?Selector
? 舉例說明幾個概念。在所有情況下,我們假設 ?Selector
? 用一個 ?HtmlResponse
? 這樣的對象:
sel = Selector(html_response)
1、選擇全部 ?<h1>? 來自HTML響應正文的元素,返回 ?Selector? 對象(即 ?SelectorList? 對象):
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> 標記并打印其類屬性:
for node in sel.xpath("http://p"):
print(node.attrib['class'])
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: