本文整理汇总了Python中db.models.User.name方法的典型用法代码示例。如果您正苦于以下问题:Python User.name方法的具体用法?Python User.name怎么用?Python User.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.models.User
的用法示例。
在下文中一共展示了User.name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_detail
# 需要导入模块: from db.models import User [as 别名]
# 或者: from db.models.User import name [as 别名]
def get_detail(html):
user = User()
cont = public.get_right(html)
if cont == '':
return None
soup = BeautifulSoup(cont, 'html.parser')
basic_modules = soup.find_all(attrs={'class': 'WB_cardwrap S_bg2'})
basic_info = soup.find_all(attrs={'class': 'li_1 clearfix'})
for each_module in basic_modules:
try:
basic_str = each_module.find(attrs={'class': 'main_title W_fb W_f14'}).get_text()
if '基本信息' in basic_str:
for each in basic_info:
each_str = each.get_text()
if '昵称:' in each_str:
user.name = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '所在地:' in each_str:
user.location = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '性别:' in each_str:
gender = each.find(attrs={'class': 'pt_detail'}).get_text()
if gender == '男':
user.gender = 1
elif gender == '女':
user.gender = 2
else:
user.gender = 0
elif '生日:' in each_str:
user.birthday = each.find(attrs={'class': 'pt_detail'}).get_text()
elif '简介:' in each_str:
description = each.find(attrs={'class': 'pt_detail'}).get_text()
user.description = description.encode('gbk', 'ignore').decode('gbk')
elif '注册时间:' in each_str:
user.register_time = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\t', '').replace(
'\r\n', '')
if '标签信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
for each in basic_info:
if '标签:' in each.get_text():
user.tags = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\t', '').replace(
'\n\n\n', '') .strip().replace('\r\n', ';')
if '教育信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
for each in basic_info:
if '大学:' in each.get_text():
user.education_info = each.find(attrs={'class': 'pt_detail'}).get_text().replace('\r\n', ',') \
.replace('\t', '').replace('\n', ';').lstrip(';').rstrip(';')
if '工作信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
jobs_info = []
for each in basic_info:
if '公司:' in each.get_text():
jobs = each.find_all(attrs={'class': 'pt_detail'})
for job in jobs:
jobs_info.append(job.get_text().replace('\r\n', '').replace('\t', '').replace('\n', ''))
user.work_info = ';'.join(jobs_info)
if '联系信息' in basic_str:
basic_info = each_module.find_all(attrs={'class': 'li_1 clearfix'})
contact_info = []
for each in basic_info:
if 'QQ:' in each.get_text():
contact_info.append(
'qq:' + each.find(attrs={'class': 'pt_detail'}).get_text().replace('\n', ''))
if '邮箱:' in each.get_text():
contact_info.append('email:' + each.find(attrs={'class': 'pt_detail'}).get_text())
if 'MSN:' in each.get_text():
contact_info.append('msn:' + each.find(attrs={'class': 'pt_detail'}).get_text())
user.contact_info = ';'.join(contact_info)
except Exception as why:
print('解析出错,具体原因为{why}'.format(why=why))
return user
示例2: addUser
# 需要导入模块: from db.models import User [as 别名]
# 或者: from db.models.User import name [as 别名]
def addUser(name, username):
user = User()
user.name = name
user.username = username
user.save()
return {'user_id': user.pk, 'success':True}