python etree xpath_Python etree.XPath方法代码示例

本文整理汇总了Python中lxml.etree.XPath方法的典型用法代码示例。如果您正苦于以下问题:Python etree.XPath方法的具体用法?Python etree.XPath怎么用?Python etree.XPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块lxml.etree的用法示例。

在下文中一共展示了etree.XPath方法的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: post

​点赞 6

# 需要导入模块: from lxml import etree [as 别名]

# 或者: from lxml.etree import XPath [as 别名]

def post(self, html):

"""

Try to play with request ...

"""

import urllib2

response = urllib2.urlopen('file://%s' % html)

data = response.read()

post = etree.HTML(data)

# find text function

find_text = etree.XPath("//text()", smart_strings=False)

LOG.info(find_text(post))

post.clear()

开发者ID:gramps-project,项目名称:addons-source,代码行数:21,

示例2: test_parse_rule

​点赞 6

# 需要导入模块: from lxml import etree [as 别名]

# 或者: from lxml.etree import XPath [as 别名]

def test_parse_rule():

"""Ensure parse_rule returns expected output."""

expr = XPath("//Num")

assert parse_rule(

rule_name='',

rule_values=dict(

description='',

expr=expr,

example="a = 1",

instead="a = int('1')",

settings=Settings(included=[], excluded=[], allow_ignore=True),

)

) == Rule(

name='',

description='',

expr=expr,

example="a = 1",

instead="a = int('1')",

settings=Settings(included=[], excluded=[], allow_ignore=True)

)

开发者ID:hchasestevens,项目名称:bellybutton,代码行数:22,

示例3: _details_prepare_merge

​点赞 6

# 需要导入模块: from lxml import etree [as 别名]

# 或者: from lxml.etree import XPath [as 别名]

def _details_prepare_merge(details):

# We may mutate the details later, so copy now to prevent

# affecting the caller's data.

details = details.copy()

# Prepare an nsmap in an OrderedDict. This ensures that lxml

# serializes namespace declarations in a stable order.

nsmap = OrderedDict((ns, ns) for ns in sorted(details))

# Root everything in a namespace-less element. Setting the nsmap

# here ensures that prefixes are preserved when dumping later.

# This element will be replaced by the root of the lshw detail.

# However, if there is no lshw detail, this root element shares

# its tag with the tag of an lshw XML tree, so that XPath

# expressions written with the lshw tree in mind will still work

# without it, e.g. "/list//{lldp}something".

root = etree.Element("list", nsmap=nsmap)

# We have copied details, and root is new.

return details, root

开发者ID:maas,项目名称:maas,代码行数:22,

示例4: _details_do_merge

​点赞 6

# 需要导入模块: from lxml import etree [as 别名]

# 或者: from lxml.etree import XPath [as 别名]

def _details_do_merge(details, root):

# Merge the remaining details into the composite document.

for namespace in sorted(details):

xmldata = details[namespace]

if xmldata is not None:

try:

detail = etree.fromstring(xmldata)

except etree.XMLSyntaxError as e:

maaslog.warning("Invalid %s details: %s", namespace, e)

else:

# Add the namespace to all unqualified elements.

for elem in detail.iter("{}*"):

elem.tag = etree.QName(namespace, elem.tag)

root.append(detail)

# Re-home `root` in a new tree. This ensures that XPath

# expressions like "/some-tag" work correctly. Without this, when

# there's well-formed lshw data -- see the backward-compatibilty

# hack futher up -- expressions would be evaluated from the first

# root created in this function, even though that root is now the

# parent of the current `root`.

return etree.ElementTree(root)

开发者ID:maas,项目名称:maas,代码行数:24,

示例5: merge_details_cleanly

​点赞 6

# 需要导入模块: from lxml import etree [as 别名]

# 或者: from lxml.etree import XPath [as 别名]

def merge_details_cleanly(details):

""

你可能感兴趣的:(python,etree,xpath)