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.)//选取同级节点
//div[@class='listpage']/span/following-sibling::a[1]
//div[@class='address-row']/table/tbody/tr[@id='submitTime']/preceding-sibling::tr[1]
(3.)//获取父级元素
//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.) | 可选符 使用|可选取若干个路径 如//p | //div
(6.). 点 用来选取当前节点
(7.).. 双点 选取当前节点的父节点
(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": "//div[@class='section']/div", # 提取规则
"child": {
"seed_url": {
"field": "seed_url", # 字段名称
"depict": "种子url",
"status": True, # 是否禁用
"type": "", # list # 字段类型
"select": "xpath", # 提取方式
"deep": False,
"split": True,
"regex": "//h4[@class='house-title']/a/@href", # 提取规则
"value_handle": [ # 内容处理
{
"name": "urljoin"
}
],
},
"house_floor": {
"field": "house_floor", # 字段名称
"depict": "所在楼层",
"status": True, # 是否禁用
"type": "", # 字段类型
# "separator": "", # list->str 分隔符 默认按","分割
"select": "xpath", # 提取方式
"deep": False,
"split": True,
"regex": "//p[@class='house-txt'][1]/text()[2]", # 提取规则
"value_handle": [ # 内容处理
],
},
"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": "//img[@class='lazy']/@data-original", # 提取规则
"value_handle": [ # 内容处理
],
},
"house_title": {
"field": "house_title", # 字段名称
"depict": "房源标题",
"status": True, # 是否禁用
"type": "", # list # 字段类