sync moved to modules
This commit is contained in:
1 parent
1dda6ce8cc
commit
13b761a81e
50 files changed
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
|
||||
def get_following_tags(element, stop_tag_pattr):
|
||||
stop_exp = re.compile(stop_tag_pattr)
|
||||
following = element.xpath('./following-sibling::*')
|
||||
tags = []
|
||||
i = 0
|
||||
while True:
|
||||
try:
|
||||
tag = following[i]
|
||||
if stop_exp.match(tag.tag):
|
||||
break
|
||||
tags.append(tag)
|
||||
except IndexError as tag:
|
||||
break
|
||||
i += 1
|
||||
return tags
|
||||
|
||||
|
||||
def get_text_following_by_tag(element, tag, contains, strip=True):
|
||||
e = element.xpath('.//%s[contains(text(), "%s")]/following-sibling::text()' % (tag, contains))
|
||||
if len(e) > 0:
|
||||
if strip:
|
||||
return e[0].strip()
|
||||
else:
|
||||
return e[0]
|
||||
else:
|
||||
return None
|
||||
Reference in new issue
Block a user