xpath

xpath select parent based on child value

跟風遠走 提交于 2020-01-24 15:11:20
问题 I am looking to select every event where the status is "Live" I am using this in Drupal's XPath XML parser and have the Context base query and xpath queries fields. (Context=This is the base query, all other queries will run in this context.) I current have: Context: ./event[./status = 'Live'] title: title Description: description <events> <event> <title>Number 1</title> <status>Draft</status> <description></description> </event> <event> <title>Number 1</title> <status>Live</status>

xpath select parent based on child value

谁说我不能喝 提交于 2020-01-24 15:11:07
问题 I am looking to select every event where the status is "Live" I am using this in Drupal's XPath XML parser and have the Context base query and xpath queries fields. (Context=This is the base query, all other queries will run in this context.) I current have: Context: ./event[./status = 'Live'] title: title Description: description <events> <event> <title>Number 1</title> <status>Draft</status> <description></description> </event> <event> <title>Number 1</title> <status>Live</status>

Register namespace with libxml++ for XPath

只愿长相守 提交于 2020-01-24 13:29:41
问题 I wrote a C++ XPath parser with the libxml++ library, which was built on the C libxml2 library. It works great when the xmlns is not present in xml but it breaks when that namespace is added. Sample xml: <A xmlns="http://some.url/something"> <B> <C>hello world</C> <B> </a> Sample XPath: string xpath = "/A/B/C" // returns nothing when xmlns is present in the XML I found this answer and tried adjusting my XPath to the following, which does work but it makes the XPath kind of obnoxious to read

Python数据采集常见的三种爬虫语法------Xpath篇

拟墨画扇 提交于 2020-01-24 07:49:54
在讲Xpath语法之前,首先我们需要了解一下Lxml库,要不然就算我们知道语法了,没有库的支持一切都是白搭,废话不多说,直接进入主题。 1、Lxml库 Lxml库的基本概念: Lxml是Python中的一个解析库,支持Xpath语法解析方式,可以用来解析Xml结构,由于Html结构和Xml结构大致相似都是树形结构,所以Lxml也可以解析Html。 Lxml库的常见模块:Etree 我先来谈谈我对这个库的认识,Etree库的作用是对爬取出来的Html页面进行初始化操作,下面简单列举一下Etree模块的用法: 1、 文本转换成HTML对象 #HTML方法 html = etree.HTML ( text ) 2、 将对象转成html文本 html = etree.HTML ( text ) result = etree.tostring ( html ) 3、 解析页面并返还Html对象 html = etree.parse ( 'text.html' ) 当然这个模块下想必不止这一些方法,Lxml库下也不止着一些模块,这边由于本人能力有限不能一一向大家介绍清楚,感兴趣的可以自己深入了解一下哈哈哈,这边草率地介绍一下爬虫解析页面时常用的三种方法。 Lxml安装: 命令行安装win+r,输入Cmd,进入终端模式(配好Python的环境变量) 2.在开发工具里面安装库包

8.正则表达式和XPath

徘徊边缘 提交于 2020-01-24 04:56:36
1.使用正则表达式爬取内涵段子 import requests import re def loadPage(page): url = "http://www.neihan8.com/article/list_5_" +page+".html" #User-Agent头 user_agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT6.1; Trident/5.0' headers = {'User-Agent': user_agent} response = requests.get(url,headers=headers) response.encoding = 'gbk' html = response.text return html if __name__=="__main__": page=input('请输入要爬取的页面:') html=loadPage(page) # with open('a.html','w') as f: # f.write(html) # 找到所有的段子内容<div class="f18 mb20"></div> # re.S 如果没有re.S 则是只匹配一行有没有符合规则的字符串,如果没有则下一行重新匹配 # 如果加上re.S 则是将所有的字符串将一个整体进行匹配,找到(.*?

Python_爬虫_xpath/bs4/re小实战

点点圈 提交于 2020-01-24 02:32:26
1 #爬取糗事百科照片(前5页)   ·##利用正则表达式 2 import requests #请求数据 4 from urllib import request #请求数据,用这个方便下载照片 5 import re #正则 6 #糗事百科照片地址 7 #普通get请求获取 8 k = 0 9 for i in range(1,6): 10 url = f'https://www.qiushibaike.com/imgrank/page/{i}/' 11 #UA伪装防止识破 12 headers = { 13 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" 14 } 15 #获取响应对象response 16 res = requests.get(url, headers=headers) 17 #利用正则表达式findall,返回列表,re.S 是用来在html中的/t/n等解决方式 18 img_urls = re.findall('<div class="thumb">.*?<img src="(.*?)".*? height="auto">.*?</div>',

Hive函数大全

时光总嘲笑我的痴心妄想 提交于 2020-01-24 00:32:25
Hive函数大全 现在虽然有很多SQL ON Hadoop的解决方案,像Spark SQL、Impala、Presto等等,但就目前来看,在基于Hadoop的大数据分析平台、数据仓库中,Hive仍然是不可替代的角色。尽管它的相应延迟大,尽管它启动MapReduce的时间相当长,但是它太方便、功能太强大了,做离线批量计算、ad-hoc查询甚至是实现数据挖掘算法,而且,和HBase、Spark都能整合使用。 如果你是做大数据分析平台和数据仓库相关的,就目前来说,我建议,Hive是必须的。 很早之前整理过Hive的函数,不过是基于0.7版本的,这两天抽时间更新了下,基于Hive0.13,比之前的完整了许多。 整理成文档,希望能给Hive初学者和Hive使用者有所帮助。,大家可关注weixin公众号:大数据技术工程师 有更多大数据精彩内容等你来看,还有大数据学习资料免费领取哦,回复关键字即可。 Hive函数大全 目录: 一、关系运算: 1. 等值比较: = 2. 等值比较:<=> 3. 不等值比较: <>和!= 4. 小于比较: < 5. 小于等于比较: <= 6. 大于比较: > 7. 大于等于比较: >= 8. 区间比较 9. 空值判断: IS NULL 10. 非空判断: IS NOT NULL 10. LIKE比较: LIKE 11. JAVA的LIKE操作: RLIKE 12.

xpath提取 html标签的文字内容

ⅰ亾dé卋堺 提交于 2020-01-23 11:30:49
问题描述: 做爬虫的过程中经常需要对html标签的文字内容进行提取,有几种情况 1.提取属性的值,2.提取标签的值,3.提取段落的所有文字 本文用的是 scrapy 的框架,用 response 做响应 1.提取属性的值 <a title="这是一个标题"> response.xpath("//a/@title").get(),可以直接得到 title 的值为:这是一个标题 注:get 方法是等同于extract()[0],getall 方法等同于extract() 官方文档1.5以后推荐使用 get 系列方法代替原来的 extract 系列方法 两种方法可以同时使用,看个人喜好 2.提取标签的值 <a title="这是一个标题">这才是标题</a> response.xpath("//a/text()").get(),可以得到 a 标签的值:这才是标题 3.提取段落所有文字 <div class="test"> <a>左青龙</a> <a>右白虎</a> <a> <span>老牛在当中</span> </a> <ul> <ul> <span>龙头在胸口</span> </ul> </ul> </div> response.xpath("//div[@class='test']").get() 这种方式可以得到值为 test 的 div 标签下的所有标签组,即: <a>左青龙<

Getting all table rows and returning them using an XPath query in CasperJS

Deadly 提交于 2020-01-23 10:39:09
问题 I'm using Casper.js to automate a regular upload. I've managed to upload the file and check if it's valid, but I'd like to parse the table which is returned if there's errors, but I get the error [error] [remote] findAll(): invalid selector provided "[object Object]":Error: SYNTAX_ERR: DOM Exception 12 . Here's the relevant part of my code: casper.then(function() { if (this.fetchText('.statusMessageContainer').match(/Sorry, the file did not pass validation. Please review the validation errors

Getting all table rows and returning them using an XPath query in CasperJS

∥☆過路亽.° 提交于 2020-01-23 10:39:07
问题 I'm using Casper.js to automate a regular upload. I've managed to upload the file and check if it's valid, but I'd like to parse the table which is returned if there's errors, but I get the error [error] [remote] findAll(): invalid selector provided "[object Object]":Error: SYNTAX_ERR: DOM Exception 12 . Here's the relevant part of my code: casper.then(function() { if (this.fetchText('.statusMessageContainer').match(/Sorry, the file did not pass validation. Please review the validation errors