本文整理汇总了Python中models.Employee.research方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.research方法的具体用法?Python Employee.research怎么用?Python Employee.research使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Employee
的用法示例。
在下文中一共展示了Employee.research方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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
示例2: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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={"id":"right_2"}, limit=1)
if not divs or len(divs) == 0:
return employee
div = divs[0]
if not os.path.exists(filename):
with open(filename, 'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
researches = [' ',' ']
tds = div.find_all(name="td",attrs={"bgcolor":"#FFFFFF","class":"ft12","valign":"top"},limit=4)
if len(tds) == 4:
researches[0] = tds[2].get_text().strip()
researches[1] = tds[3].get_text().strip()
employee.research = researches[0] + ";" +researches[1]
print "research:" + employee.research
# 使用纯文本方式处理
lines = div.stripped_strings
# text=div.get_text(strip=True)
parser = ProfileParser(lines=lines,employee=employee,ignore=set(['research']))
return parser.parse()
示例3: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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()
示例4: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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_="xq_teacher", limit=1)
if not divs or len(divs) == 0:
return employee
div = divs[0]
if not os.path.exists(filename):
with open(filename, 'wb') as fp:
content = div.prettify()
fp.write(content)
fp.close()
# 找到科研方向
details = div.find_all("div",class_="con01_t",limit=3)
if details and len(details) >= 2:
employee.research = details[1].get_text()
employee.research = ''.join(employee.research.split())
# 过滤掉太短的串
if len(employee.research) <= (len(u'研究方向')+1):
employee.research = ''
else:
employee.research.replace(',',',')
# 解析其他各人信息
infos = div.find_all("div",class_="wz_teacher",limit=1)
if infos and len(infos) != 0:
# 使用纯文本方式处理
lines = infos[0].stripped_strings
parser = ProfileParser(lines=lines,employee=employee,set_attr_hook=set_attr_hook,force_email=True)
return parser.parse()
else:
return employee
示例5: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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
示例6: handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [as 别名]
def handler(tag):
dd_tables = {
"Email":"email",
"Phone":"tel",
"Homepage":"profile",
'Math Fields':'research'
}
h3 = tag.find_all(name='h3')
if not h3:
return None
employee = Employee()
employee.name = h3[0].get_text() or ''
employee.name = ''.join(employee.name.split())
title_spans = tag.find_all(name="span",class_="faculty-title")
employee.title = title_spans[0].get_text()
#employee.title = ''.join(employee.title.split())
tds = tag.find_all(name='dt',class_="faculty-info")
if not tds or len(tds) < 5:
return None
employee.email = tds[0].get_text()
employee.email = ''.join(employee.email.split())
employee.tel = tds[1].get_text()
employee.tel = ''.join(employee.tel.split())
employee.profile = tds[3].get_text()
employee.profile = ''.join(employee.profile.split())
employee.research = tds[4].get_text()
#employee.research = ''.join(employee.research.split())
return employee
示例7: profile_handler
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import research [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