本文整理汇总了Python中pyquery.PyQuery.prev方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.prev方法的具体用法?Python PyQuery.prev怎么用?Python PyQuery.prev使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyquery.PyQuery
的用法示例。
在下文中一共展示了PyQuery.prev方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_headers
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import prev [as 别名]
def _get_headers(self, xml_table):
"""Extract headers from table. Headers may be stored in the
<thead> element, or in one or more <tr> elements, or in an
<h1 class="table"> element preceding the table. This method checks
all of the above until it finds a valid table header (verified
using the _is_mri_header() method)."""
# Parse table
qtable = PyQuery(xml_table)
# Get headers from <thead> / <tr> tags
# Get <thead> / <tr> tags
trs = qtable("thead,tr")
# Check up to _max_header_tries or the number of
# <thead> / <tr> tags, whichever is least
ntry = min(trs.length, self._max_header_tries)
# Loop over rows in reverse order
# Deals with empty / incomplete headers at the
# top of the table
for tryidx in range(0, ntry)[::-1]:
# Extract text from <th> / <td> children
headers = PyQuery(trs[tryidx])("th,td").map(self._get_text)[:]
# Done if current value is a valid header
if self._is_mri_header(headers):
return headers
# Get headers from <h1 class="table"> tags
h1_table = qtable.prev("h1.table").text()
if h1_table:
headers = re.split("\s+", h1_table)
# Done if current value is a valid header
if self._is_mri_header(headers):
return headers
# No headers found
return []