本文整理汇总了Python中models.Employee.title方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.title方法的具体用法?Python Employee.title怎么用?Python Employee.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Employee
的用法示例。
在下文中一共展示了Employee.title方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
tds = tag.find_all(name='td')
if not tds:
print("len(tds) == 0")
return None
employee = Employee()
if len(tds) < 5:
print("len(tds) = %d"%(len(tds)))
return None
name_tag = None
name_tag_idx = 0
if len(tds) == 5:
name_tag_idx = 0
name_tag = tds[name_tag_idx]
elif len(tds) > 5:
name_tag_idx = 1
name_tag = tds[name_tag_idx]
employee.name = name_tag.get_text()
employee.name = employee.name.strip()
if employee.name == u'姓名':
return None
ass = name_tag.find_all('a')
if ass and len(ass) != 0:
employee.url = ass[0]['href']
employee.title = tds[name_tag_idx+1].get_text().strip()
employee.email = tds[name_tag_idx+2].get_text().strip()
employee.tel = tds[name_tag_idx+3].get_text().strip()
return employee
示例2: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
tds = tag.find_all(name='td')
if not tds:
print("len(tds) == 0")
return None
employee = Employee()
if len(tds) < 4:
print("len(tds) = %d"%(len(tds)))
return None
name_tag = tds[0]
employee.name = name_tag.get_text()
employee.name = employee.name.strip()
if employee.name == u'姓名':
return None
ass = name_tag.find_all('a')
if ass and len(ass) != 0:
employee.url = ass[0]['href']
employee.title = tds[2].get_text().strip()
employee.departments = tds[3].get_text().strip()
return employee
示例3: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
tds = tag.find_all(name='td')
if not tds or len(tds) != 5:
return None
name = tds[0].get_text()
if not name or len(name) == 0:
return None
employee = Employee()
employee.name = ''.join(name.split())
if employee.name == u'姓名':
return None
ass = tag.find_all('a')
if ass:
employee.url = ass[0]['href']
title = tds[3].get_text()
if title and len(title) != 0:
title = ''.join(title.split())
title = title.replace(',',',')
employee.title = title
print title
research = tds[4].get_text()
if research and len(research) != 0:
employee.research = research.strip()
employee.research = employee.research.replace(',',',')
return employee
示例4: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def profile_handler(doc, name, url, path):
filename = os.path.join(path, name + ".html")
employee = Employee(name=name, url=url)
# 只保存名称和个人主页,个人简历文件另存当前目录
soup = BeautifulSoup(doc, Config.SOUP_PARSER)
divs = soup.find_all(name="div", class_="box_rt01 list", limit=1)
if not divs or len(divs) == 0:
div = soup
else:
div = divs[0]
with open(filename, 'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
h3s = div.find_all('h3')
if h3s and len(h3s) != 0:
title = h3s[0].get_text()
title = ''.join(title.split())
print title
for t in PROFILE_TITLES:
if t in title:
employee.title = title
print "got => " + title
break
else:
print "not found h3"
# 使用纯文本方式处理
lines = div.stripped_strings
# text=div.get_text(strip=True)
parser = ProfileParser(lines=lines,employee=employee,force_email=True)
return parser.parse()
示例5: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
tds = tag.find_all("td")
if not tds or len(tds) != 4:
return None
employee = Employee()
ass = tag.find_all('a')
if ass and len(ass) != 0:
employee.url = ass[0]['href']
employee.name = tds[0].get_text().strip()
employee.name = ''.join(employee.name.split())
title = tds[1].get_text()
if title and len(title) != 0:
employee.title = ''.join(title.split())
email = tds[3].get_text()
if email and len(email) != 0:
employee.email = ''.join(email.split())
tel = tds[2].get_text()
if tel and len(tel) != 0:
employee.tel = ''.join(tel.split())
return employee
示例6: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
name = tag.get_text()
name = ''.join(name.split())
names = name.split('_')
name = names[0]
employee = Employee(url=tag['href'], name=name)
if len(names) >= 2:
employee.title = names[1]
return employee
示例7: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
tds = tag.find_all(name='td')
if not tds or len(tds) != 3:
return None
employee = Employee()
employee.name = tds[0].get_text() or ''
employee.name = ''.join(employee.name.split())
# 过滤表头
if employee.name == u'姓名':
return None
employee.title = tds[1].get_text()
employee.title = ''.join(employee.title.split())
employee.email = tds[2].get_text()
employee.email = ''.join(employee.email.split())
employee.email = email_value_strip(employee.email)
# print(tag)
return employee
示例8: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def profile_handler(doc, name, url, path):
filename = os.path.join(path, name + ".html")
employee = Employee(name=name, url=url)
# 只保存名称和个人主页,个人简历文件另存当前目录
soup = BeautifulSoup(doc, Config.SOUP_PARSER)
divs = soup.find_all(name="div", attrs={"class":"page_right addpage_right"}, limit=1)
if not divs or len(divs) == 0:
div= soup
else:
div = divs[0]
if not os.path.exists(filename):
with open(filename, 'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
tds = div.find_all('td')
if tds and len(tds) == 11:
department = tds[2].get_text()
if department:
department = ''.join(department.split())
if department and len(department) != 0:
employee.departments = department
title = tds[4].get_text()
if title:
title = ''.join(title.split())
if title and len(title) != 0:
employee.title = title
email = tds[8].get_text()
if email:
email = ''.join(email.split())
if email and len(email) != 0:
employee.email = email
research = tds[10].get_text()
if research:
research = ''.join(research.split())
if research and len(research) != 0:
employee.research = research
divs = soup.find_all(name="div", attrs={"class":"text_more"}, limit=1)
if divs and len(divs) != 0:
div = divs[0]
# 使用纯文本方式处理
lines = div.stripped_strings
# text=div.get_text(strip=True)
parser = ProfileParser(lines=lines,employee=employee,set_attr_hook=set_attr_hook)
return parser.parse()
示例9: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
employee = Employee()
names = tag.get_text()
names = ''.join(names.split())
names = names.replace(')','')
names = names.replace(')','')
names = names.replace('(','(')
names = names.split('(')
employee.name = names[0]
if len(names) >= 2:
employee.title = names[1]
employee.url = tag['href']
print employee.name, employee.title
return employee
示例10: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
employee = Employee(url=tag['href'])
# 刘全勇: 硕士生导师
string = ''.join(tag.get_text().split())
string_splits = string.split(u':')
if len(string_splits) == 1:
employee.name = string_splits[0]
elif len(string_splits) == 2:
employee.name = string_splits[0]
employee.title = string_splits[1]
else:
return None
print("name:"+employee.name )
return employee
示例11: add_rp14a_form
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def add_rp14a_form(dictionary):
with contextlib.closing(make_session()) as session:
employee = Employee()
employee.nino = dictionary["employee_national_insurance_number"]
employee.date_of_birth = dictionary["employee_date_of_birth"]
employee.title = dictionary["employee_title"]
employee.forenames = dictionary["employee_forenames"]
employee.surname = dictionary["employee_surname"]
employee.ip_number = "12345" #TODO: should we collect this on the form?
employee.employer_name = dictionary["employer_name"]
#TODO: Remove hack around decimals in JSON
for decimal_key in ["employee_owed_wages_in_arrears", "employee_holiday_owed", "employee_basic_weekly_pay"]:
if decimal_key in dictionary:
dictionary[decimal_key] = str(dictionary[decimal_key])
employee.hstore = {key: json.dumps(value, default=encode_special_types)
for key, value in dictionary.items()}
session.add(employee)
session.commit()
示例12: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
symbols = set([u'首页',u'第一页',u'下一页',u'最后页 ',u'上一页',])
if not tag.string:
return None
name = tag.string.strip()
if name in symbols:
return None
employee = Employee(name=name, url=tag['href'])
# 根据预定的关键词推测身分
for keyword in PROFILE_TITLES:
idx = name.find(keyword)
if idx != -1:
employee.name = name[:idx]
employee.title = name[idx:]
break
return employee
示例13: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def handler(tag):
name_symbol = u'姓名'
tds = tag.find_all('td')
if len(tds) != 7:
return None
if tds[0].get_text().strip() == name_symbol:
return None
employee = Employee()
ass = tds[0].find_all('a')
if len(ass) != 0:
employee.url = ass[0]['href']
employee.name = tds[0].get_text().strip()
employee.email = tds[2].get_text().strip()
employee.title = tds[3].get_text().strip()
employee.research = tds[6].get_text().strip()
employee.research.replace('\n','.')
print employee.name,employee.email,employee.title
return employee
示例14: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def profile_handler(doc,name,url,path):
symbols = {
u'个人主页:' :'profile',
u'研究方向:' :'research',
u'电话:':'tel',
u'电话':'tel'
}
filename = path+name+".html"
employee = Employee(name=name,url=url)
# 太乱了,只保存名称和个人主页,个人简历文件另存当前目录
soup = BeautifulSoup(doc, Config.SOUP_PARSER)
divs = soup.find_all(id="sub_main",limit=1)
if not divs or len(divs) == 0:
# xml
members = soup.find_all(name="member",limit=1)
if not members or len(members) == 0:
print("id:main or sub_main not found")
#print doc
return employee
member = members[0]
# title
names = member.find_all('name')
if not names and len(names) != 0:
name = name[0].string
if name:
idx = name.find(' ')
if idx != -1:
employee.title = name[idx:]
if member.field:
employee.research = member.field.string or ''
if member.homepage:
employee.profile = member.homepage.string or ''
if member.contact:
if member.contact.string:
for i,c in enumerate(member.contact.string):
if c.isdigit():
employee.tel += c
with open(filename,'wb') as fp:
content = member.prettify()
fp.write(content)
fp.close()
return employee
div = divs[0]
with open(filename,'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
h4s = div.find_all('h4')
if not h4s and len(h4s) != 0:
name = h4s[0].string
idx = name.find(' ')
if idx != -1:
employee.tite = name[idx:]
employee.tite = ''.join(employee.tite.split())
lis = div.find_all("li",limit=8)
if not lis or len(lis) == 0:
return employee
res = lis[0]
# 解析详细内容
for count,tag in enumerate(lis[0].children):
text = tag.string
if not text:
continue
if len(text) == 0:
continue
text = ''.join(text.split())
if '@' in text:
employee.email = text
continue
for symbol,name in symbols.items():
idx = text.find(symbol)
if idx != -1:
idx += len(symbol)
value = text[idx:]
if hasattr(employee, name):
setattr(employee, name, value)
print (name + ":" + value)
else:
print ("no attr %s in employee" % name)
break
return employee
示例15: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import title [as 别名]
def profile_handler(doc,name,url,path):
# employee可用属性(url, name, email, tel, title, profile, research, departments,fax,addr):
symbols = {
'email': u'电子邮件:',
'tel': u'办公电话:',
'addr': u'办公地址:',
'research':u'研究方向:'
}
employee = None
soup = BeautifulSoup(doc, Config.SOUP_PARSER)
divs = soup.find_all("td",attrs={"valign":"top"},limit=1)
if not divs or len(divs) == 0:
return employee
div = divs[0]
employee = Employee()
# save file
filename = path+name+".html"
with open(filename,'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
# parse name
name_h3 = div.h3
if name_h3:
employee.name = name_h3.string.strip(' \t\n\r')
else:
print name_h3
# parse title
dls = soup.dl
if dls and len(dls) >= 1:
print dls
if dls.dt:
employee.title = dls.dt.string
# parse everything
for tag in dls.children:
if not tag.string:
continue
text = tag.string.strip(' \t\n\r')
if len(text) == 0:
continue
for name, symbol in symbols.items():
idx = text.find(symbol)
if idx != -1:
idx += len(symbol)
value = text[idx:]
if hasattr(employee, name):
setattr(employee, name, value)
# print (name + ":" + value)
else:
print ("no attr %s in employee" % name)
break
# parse profile
teachcontent = soup.find_all("div",class_="teachcontent",limit=1)
if len(teachcontent) != 0:
content = teachcontent[0]
link= content.a
if link:
employee.url = link['href']
return employee