99re热视频这里只精品,久久久天堂国产精品女人,国产av一区二区三区,久久久精品成人免费看片,99久久精品免费看国产一区二区三区

scrapy 2.3 HTML響應的選擇器示例

2021-06-04 10:53 更新

這里有一些 ?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'])
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號