Example #1
0
	def profile(self, renrenId, no_use=None):
		"""profile('234234') --> (record:dict(), timecost:str)
		return (None, error_info) if error"""
		runtime_start=time.time()
		pageStyle='profile_detail'
		html_content=self._download(urls[pageStyle].format(renrenId))
		if html_content is None:
			return None, 'timout'
		elif html_content[0:30].find('<div class="col-left">') > -1:
			pf=parse.profile_detail(itemReg[pageStyle].findall(html_content))
		else:
			#TODO:check whether account safety
			pageStyle='profile_mini'
			pf=parse.profile_mini(itemReg[pageStyle].findall(html_content))
		runtime=time.time()-runtime_start
		return pf, format_time(runtime)
Example #2
0
	def profile(self, renrenId, no_use=None):
		"""profile('234234') --> (record:dict(), timecost:str)
		return (None, error_info) if error"""
		runtime_start=time.time()
		pageStyle='profile_detail'
		html_content=self._download(urls[pageStyle].format(renrenId))
		if html_content is None:
			return None, 'timout'
		elif html_content[0:30].find('<div class="col-left">') > -1:
			pf=parse.profile_detail(itemReg[pageStyle].findall(html_content))
		else:
			#TODO:check whether account safety
			pageStyle='profile_mini'
			pf=parse.profile_mini(itemReg[pageStyle].findall(html_content))
		runtime=time.time()-runtime_start
		return pf, format_time(runtime)
Example #3
0
	def test_profile_detail(self):
		contents={
			#some items with no space
			"""<dt>性别:</dt><dd>女</dd>,\
			<dt>大学:</dt><dd><a st>北学</a>-<a st>2013年</a>-<a st>学院</a><br><a st>理工大学</a>-<a st>2011年</a>-<a st>生命学院</a><br></dd>,\
			<dt>小学:</dt><dd><a st>一个小学</a>-<a st>1991年</a><a st>青岛二小</a>-<a st>2001年</a></dd>"""
			:{'性别': '女',
				'大学': '北学-2013年-学院<br>理工大学-2011年-生命学院<br>',
				'小学': '一个小学-1991年青岛二小-2001年'},
			#some items with space and \n \t
			"""<dt> 性 别 : </dt> <dd> 女 </dd> , \
			<dt> 大 学 : </dt>\n\\n<dd>\n\\n<a st>\n\\n北京中医药大学\n</a> - <a st>\n 2013年\n </a> - <a st> 东方学院 </a><br>\
				<a st> 北京理工大学\t\t</a> - <a st> 2011年 </a> - <a st> 生命科学与技术学院六院 </a><br></dd>,\
			<dt> 小 学 : </dt><dd><a st> 一个小学 </a> - <a st> 1991年 </a><a st> 青岛二小 </a> - <a st> 2001年 </a></dd>"""
			:{'性别': '女',
				'大学': '北京中医药大学 - 2013年 - 东方学院 <br> 北京理工大学 - 2011年 - 生命科学与技术学院六院 <br>',
				'小学': '一个小学 - 1991年 青岛二小 - 2001年'},
			#no items or None
			"""no item""":{},None:None}
		for  content,expt in contents.items():
			if content is not None:
				content=content.split(',')
				self.assertEquals(parse.profile_detail(content),expt)
Example #4
0
	def test_profile_detail(self):
		contents={
			#some items with no space
			"""<dt>性别:</dt><dd>女</dd>,\
			<dt>大学:</dt><dd><a st>北学</a>-<a st>2013年</a>-<a st>学院</a><br><a st>理工大学</a>-<a st>2011年</a>-<a st>生命学院</a><br></dd>,\
			<dt>小学:</dt><dd><a st>一个小学</a>-<a st>1991年</a><a st>青岛二小</a>-<a st>2001年</a></dd>"""
			:{'性别': '女',
				'大学': '北学-2013年-学院<br>理工大学-2011年-生命学院<br>',
				'小学': '一个小学-1991年青岛二小-2001年'},
			#some items with space and \n \t
			"""<dt> 性 别 : </dt> <dd> 女 </dd> , \
			<dt> 大 学 : </dt>\n\\n<dd>\n\\n<a st>\n\\n北京中医药大学\n</a> - <a st>\n 2013年\n </a> - <a st> 东方学院 </a><br>\
				<a st> 北京理工大学\t\t</a> - <a st> 2011年 </a> - <a st> 生命科学与技术学院六院 </a><br></dd>,\
			<dt> 小 学 : </dt><dd><a st> 一个小学 </a> - <a st> 1991年 </a><a st> 青岛二小 </a> - <a st> 2001年 </a></dd>"""
			:{'性别': '女',
				'大学': '北京中医药大学 - 2013年 - 东方学院 <br> 北京理工大学 - 2011年 - 生命科学与技术学院六院 <br>',
				'小学': '一个小学 - 1991年 青岛二小 - 2001年'},
			#no items or None
			"""no item""":{},None:None}
		for  content,expt in contents.items():
			if content is not None:
				content=content.split(',')
				self.assertEquals(parse.profile_detail(content),expt)