def person_info_parse(person_driver): name = person_driver.find_element_by_class_name('person_name').text href = person_driver.find_element_by_class_name('person_addr').find_element_by_class_name('W_linkb').text person_addr_driver = person_driver.find_element_by_class_name('person_addr').find_elements_by_tag_name('span') gender = person_addr_driver[0].get_attribute('title') address = person_addr_driver[1].text.encode('utf-8').split(',')[1] person_num_driver = person_driver.find_element_by_class_name('person_num').find_elements_by_tag_name('a') focus_num = int(person_num_driver[0].text) fans_num = int(person_num_driver[1].text) weibo_num = int(person_num_driver[2].text) infos = info_parse(person_driver) company = infos.get('职业信息') edu = infos.get('教育信息') person_info = FansInfo() person_info.name = name person_info.address = address person_info.company = company person_info.edu = edu person_info.gender = gender person_info.href = href person_info.focus_num = focus_num person_info.fans_num = fans_num person_info.weibo_num = weibo_num person_info.focus_action = person_driver.find_element_by_class_name('person_adbtn').find_elements_by_tag_name('a') return person_info
def person_info_parse(person_driver): name = person_driver.find_element_by_class_name('person_name').text href = person_driver.find_element_by_class_name( 'person_addr').find_element_by_class_name('W_linkb').text person_addr_driver = person_driver.find_element_by_class_name( 'person_addr').find_elements_by_tag_name('span') gender = person_addr_driver[0].get_attribute('title') address = person_addr_driver[1].text.encode('utf-8').split(',')[1] person_num_driver = person_driver.find_element_by_class_name( 'person_num').find_elements_by_tag_name('a') focus_num = int(person_num_driver[0].text) fans_num = int(person_num_driver[1].text) weibo_num = int(person_num_driver[2].text) infos = info_parse(person_driver) company = infos.get('职业信息') edu = infos.get('教育信息') person_info = FansInfo() person_info.name = name person_info.address = address person_info.company = company person_info.edu = edu person_info.gender = gender person_info.href = href person_info.focus_num = focus_num person_info.fans_num = fans_num person_info.weibo_num = weibo_num person_info.focus_action = person_driver.find_element_by_class_name( 'person_adbtn').find_elements_by_tag_name('a') return person_info
def __focus_parse(focus_driver): fans = FansInfo() wrapper_driver = focus_driver.find_element_by_xpath( ".//a[@node-type='screen_name']") fans.id = wrapper_driver.get_attribute('usercard').encode('utf-8')[3:] fans.name = wrapper_driver.get_attribute('title').encode('utf-8') fans.href = wrapper_driver.get_attribute('href').encode('utf-8') fans.driver = focus_driver relationship = focus_driver.find_element_by_class_name( 'statu').text.encode('utf-8') if relationship == '互相关注': fans.relationship = CommonConst.Const.FOCUS_EACH_OTHER else: fans.relationship = CommonConst.Const.ME_FOCUS_HIM return fans
def fans_parse(fans_driver): print('解析关注中的好友列表') href = fans_driver.find_element_by_class_name('S_txt1').get_attribute('href') nums_driver = fans_driver.find_elements_by_class_name('count') focus_num = nums_driver[0].text fans_num = nums_driver[1].text weibo_num = nums_driver[2].text address = fans_driver.find_element_by_class_name('info_add').find_element_by_tag_name('span').text.encode('utf-8').split(' ') country = address[0] if len(address) > 1: city = address[1] else: city = '' address = (country, city) fans = FansInfo() fans.href = href fans.focus_num = focus_num fans.fans_num = fans_num fans.weibo_num = weibo_num fans.address = address return fans
def fans_parse(fans_driver): print('解析关注中的好友列表') href = fans_driver.find_element_by_class_name('S_txt1').get_attribute( 'href') nums_driver = fans_driver.find_elements_by_class_name('count') focus_num = nums_driver[0].text fans_num = nums_driver[1].text weibo_num = nums_driver[2].text address = fans_driver.find_element_by_class_name( 'info_add').find_element_by_tag_name('span').text.encode( 'utf-8').split(' ') country = address[0] if len(address) > 1: city = address[1] else: city = '' address = (country, city) fans = FansInfo() fans.href = href fans.focus_num = focus_num fans.fans_num = fans_num fans.weibo_num = weibo_num fans.address = address return fans