W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
?Selector
? 也有 ?.re()
? 使用正則表達式提取數(shù)據(jù)的方法。但是,與使用不同 ?.xpath()
? 或 ?.css()
? 方法, ?.re()
? 返回字符串列表。所以你不能構造嵌套的 ?.re()
? 電話。
下面是一個用于從 HTML code 以上:
>>> response.xpath('//a[contains(@href, "image")]/text()').re(r'Name:\s*(.*)')
['My image 1',
'My image 2',
'My image 3',
'My image 4',
'My image 5']
另外還有一個助手在做往復運動 ?.get()
? (及其別名) ?.extract_first()
? 為 ?.re()
? 命名 ?.re_first()
? . 使用它只提取第一個匹配字符串:
>>> response.xpath('//a[contains(@href, "image")]/text()').re_first(r'Name:\s*(.*)')
'My image 1'
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: