本文整理汇总了Python中lxml.etree.XML.find方法的典型用法代码示例。如果您正苦于以下问题:Python XML.find方法的具体用法?Python XML.find怎么用?Python XML.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.etree.XML
的用法示例。
在下文中一共展示了XML.find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_search
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import find [as 别名]
def do_search(param, sort, page=1, rows=100):
(reply, solr_select, q_list) = run_solr_query(param, rows, page, sort)
is_bad = False
if reply.startswith('<html'):
is_bad = True
if not is_bad:
try:
root = XML(reply)
except XMLSyntaxError:
is_bad = True
if is_bad:
m = re_pre.search(reply)
return web.storage(
facet_counts = None,
docs = [],
is_advanced = bool(param.get('q', 'None')),
num_found = None,
solr_select = solr_select,
q_list = q_list,
error = (web.htmlunquote(m.group(1)) if m else reply),
)
docs = root.find('result')
return web.storage(
facet_counts = read_facets(root),
docs = docs,
is_advanced = bool(param.get('q', 'None')),
num_found = (int(docs.attrib['numFound']) if docs is not None else None),
solr_select = solr_select,
q_list = q_list,
error = None,
)
示例2: get_article_by_search_wap
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import find [as 别名]
def get_article_by_search_wap(keyword, wap_dict):
datas = []
for i in wap_dict['items']:
item = str_to_bytes(i).replace(b'\xee\x90\x8a' + str_to_bytes(keyword) + b'\xee\x90\x8b',
str_to_bytes(keyword))
root = XML(item)
display = root.find('.//display')
datas.append({
'gzh': {
'profile_url': display.find('encGzhUrl').text,
'open_id': display.find('openid').text,
'isv': display.find('isV').text,
'wechat_name': display.find('sourcename').text,
'wechat_id': display.find('username').text,
'headimage': display.find('headimage').text,
'qrcode': display.find('encQrcodeUrl').text,
},
'article': {
'title': display.find('title').text,
'url': display.find('url').text, # encArticleUrl
'main_img': display.find('imglink').text,
'abstract': display.find('content168').text,
'time': display.find('lastModified').text,
},
})
return datas
示例3: do_search
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import find [as 别名]
def do_search(param, sort, page=1, rows=100, spellcheck_count=None):
(reply, solr_select, q_list) = run_solr_query(
param, rows, page, sort, spellcheck_count)
is_bad = False
if not reply or reply.startswith('<html'):
is_bad = True
if not is_bad:
try:
root = XML(reply)
except XMLSyntaxError:
is_bad = True
if is_bad:
m = re_pre.search(reply)
return web.storage(
facet_counts = None,
docs = [],
is_advanced = bool(param.get('q')),
num_found = None,
solr_select = solr_select,
q_list = q_list,
error = (web.htmlunquote(m.group(1)) if m else reply),
)
spellcheck = root.find("lst[@name='spellcheck']")
spell_map = {}
if spellcheck is not None and len(spellcheck):
for e in spellcheck.find("lst[@name='suggestions']"):
assert e.tag == 'lst'
a = e.attrib['name']
if a in spell_map or a in ('sqrt', 'edition_count'):
continue
spell_map[a] = [i.text for i in e.find("arr[@name='suggestion']")]
docs = root.find('result')
return web.storage(
facet_counts = read_facets(root),
docs = docs,
is_advanced = bool(param.get('q')),
num_found = (int(docs.attrib['numFound']) if docs is not None else None),
solr_select = solr_select,
q_list = q_list,
error = None,
spellcheck = spell_map,
)
示例4: parse_error
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import find [as 别名]
def parse_error(xml_str):
error = {}
doc = XML(xml_str)
if doc.tag == 'error':
elem = doc
elif doc.tag == 'customers':
elem = doc.find('.//error')
else:
raise Exception("Can't find error element in '%s'" % xml_str)
client_log.debug(elem)
error['id'] = elem.attrib['id']
error['code'] = elem.attrib['code']
error['aux_code'] = elem.attrib['auxCode']
error['message'] = elem.text
return error
示例5: parse_error
# 需要导入模块: from lxml.etree import XML [as 别名]
# 或者: from lxml.etree.XML import find [as 别名]
def parse_error(xml_str):
error = {}
doc = XML(xml_str)
if doc.tag == "error":
elem = doc
elif doc.tag == "customers":
elem = doc.find(".//error")
else:
raise Exception("Can't find error element in '%s'" % xml_str)
client_log.debug(elem)
error["id"] = elem.attrib["id"]
error["code"] = elem.attrib["code"]
error["aux_code"] = elem.attrib["auxCode"]
error["message"] = elem.text
return error