1.xpath常用匹配:
(1.)//模糊查詢
//div[contains(text(),"history-loadmore") and not(contains(@class, "history-loadmore hide"))]
//div[@class='bookTel']/span[@class='tel']/strong[1][contains(text(),'-')]/text()
(2.)//選取同級(jí)節(jié)點(diǎn)
//div[@class='listpage']/span/following-sibling::a[1]
//div[@class='address-row']/table/tbody/tr[@id='submitTime']/preceding-sibling::tr[1]
(3.)//獲取父級(jí)元素
//div[@class='page-box house-lst-page-box']/parent::div
//div[@class and @id]
//div[@id="myid"]//text()
//div[@class='lp-main-page']/a[@class='page-num '][last()]/text()
(4.)//大于1
a[position()>1]
li[not(@class)]preceding
(5.)? | 可選符 使用|可選取若干個(gè)路徑 如//p | //div
(6.). 點(diǎn) 用來選取當(dāng)前節(jié)點(diǎn)
(7.).. 雙點(diǎn) 選取當(dāng)前節(jié)點(diǎn)的父節(jié)點(diǎn)
(8.)\w 是 [A-Za-z0-9_]
(9.)\d 是 [0-9]
2.child的用法:
"url_page": {
? ? "seed_urls": {
? ? ? ? "field": "seed_urls",? # 字段名稱
? ? ? ? "depict": "種子url",
? ? ? ? "status": True,? # 是否禁用
? ? ? ? "type": [],? # list? # 字段類型
? ? ? ? "select": "xpath",? # 提取方式
? ? ? ? "deep": False,
? ? ? ? "split": True,
? ? ? ? "regex": "http://div[@class='section']/div",? # 提取規(guī)則
? ? ? ? "child": {
? ? ? ? ? ? "seed_url": {
? ? ? ? ? ? ? ? "field": "seed_url",? # 字段名稱
? ? ? ? ? ? ? ? "depict": "種子url",
? ? ? ? ? ? ? ? "status": True,? # 是否禁用
? ? ? ? ? ? ? ? "type": "",? # list? # 字段類型
? ? ? ? ? ? ? ? "select": "xpath",? # 提取方式
? ? ? ? ? ? ? ? "deep": False,
? ? ? ? ? ? ? ? "split": True,
? ? ? ? ? ? ? ? "regex": "http://h4[@class='house-title']/a/@href",? # 提取規(guī)則
? ? ? ? ? ? ? ? "value_handle": [? # 內(nèi)容處理
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? "name": "urljoin"
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ],
? ? ? ? ? ? },
? ? ? ? ? ? "house_floor": {
? ? ? ? ? ? ? ? "field": "house_floor",? # 字段名稱
? ? ? ? ? ? ? ? "depict": "所在樓層",
? ? ? ? ? ? ? ? "status": True,? # 是否禁用
? ? ? ? ? ? ? ? "type": "",? # 字段類型
? ? ? ? ? ? ? ? # "separator": "",? # list->str 分隔符 默認(rèn)按","分割
? ? ? ? ? ? ? ? "select": "xpath",? # 提取方式
? ? ? ? ? ? ? ? "deep": False,
? ? ? ? ? ? ? ? "split": True,
? ? ? ? ? ? ? ? "regex": "http://p[@class='house-txt'][1]/text()[2]",? # 提取規(guī)則
? ? ? ? ? ? ? ? "value_handle": [? # 內(nèi)容處理
? ? ? ? ? ? ? ? ],
? ? ? ? ? ? },
? ? ? ? ? ? "thumbnails": {
? ? ? ? ? ? ? ? "field": "thumbnails",? # 字段名稱
? ? ? ? ? ? ? ? "depict": "縮略圖",
? ? ? ? ? ? ? ? "status": True,? # 是否禁用
? ? ? ? ? ? ? ? "type": "",? # list? # 字段類型
? ? ? ? ? ? ? ? "select": "xpath",? # 提取方式//ul[@class='listUl']/li/div[@class='img_list']/a/img/@src
? ? ? ? ? ? ? ? "deep": False,
? ? ? ? ? ? ? ? "split": True,
? ? ? ? ? ? ? ? "regex": "http://img[@class='lazy']/@data-original",? # 提取規(guī)則
? ? ? ? ? ? ? ? "value_handle": [? # 內(nèi)容處理
? ? ? ? ? ? ? ? ],
? ? ? ? ? ? },
? ? ? ? ? ? "house_title": {
? ? ? ? ? ? ? ? "field": "house_title",? # 字段名稱
? ? ? ? ? ? ? ? "depict": "房源標(biāo)題",
? ? ? ? ? ? ? ? "status": True,? # 是否禁用
? ? ? ? ? ? ? ? "type": "",? # list? # 字段類