本文整理汇总了Python中bs4.Tag.find方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.find方法的具体用法?Python Tag.find怎么用?Python Tag.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bs4.Tag
的用法示例。
在下文中一共展示了Tag.find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_all_data
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import find [as 别名]
def fetch_all_data(post: Tag):
title = post.find(style='font-size: 18px').text
post_datetime = grab_post_datetime(post)
file_name = clean_filename(post_datetime + '-' + title)
print(' Creating folder: ' + file_name)
makedirs(file_name)
chdir(file_name)
download_images(post)
text = post.find(style='font-size: 13px').text
print(' Saving post text')
with open('post_text.txt', 'w+', encoding='utf-8') as post_text_file:
post_text_file.write(text)
chdir('..')
post_monolith.append((post_datetime, title + '\n' + text + '\n\n'))
示例2: convert_to_dict
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import find [as 别名]
def convert_to_dict(rule_tag: Tag):
nonlocal order
ret_dict = {}
atom = rule_tag.find("Atom")
try:
pattern = atom['value']
ret_dict['order'] = order
# some fixes for rule kinds
# we've got: prefix, inside, suffix, exact
if atom['kind'] == "prefix":
ret_dict['pattern'] = pattern + "\.\*"
elif atom['kind'] == "inside":
ret_dict['pattern'] = "\.\*"+pattern+"\.\*"
elif atom['kind'] == "suffix":
ret_dict['pattern'] = "\.\*"+pattern
else:
ret_dict['pattern'] = pattern
ret_dict['actions'] = []
for action in rule_tag.children:
if action is not None:
try:
if action.name.lower() in actions:
ret_dict['actions'].append(action.name.lower())
except AttributeError:
pass
order += 1
return ret_dict
except TypeError:
return None
示例3: get_date
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import find [as 别名]
def get_date(result: Tag) -> str:
try:
return result.find("p", {"class": "date_x"}).text.strip()
except:
return ""
示例4: grab_post_datetime
# 需要导入模块: from bs4 import Tag [as 别名]
# 或者: from bs4.Tag import find [as 别名]
def grab_post_datetime(post: Tag) -> string:
time_text = post.find(id='publicerad').text
date_time_string = re.search(r'Tidpunkt:(.+)[|]', time_text).group(1).strip()
post_datetime = datetime.datetime.strptime(date_time_string, '%d / %m - %Y %H:%M').strftime('%y-%m-%d_%H:%M')
return post_datetime