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 show_fans_info(weibo_driver, webdriver): img_driver = weibo_driver.find_element_by_xpath(".//div[@class='WB_face W_fl']").find_element_by_tag_name('img') ActionChains(webdriver).move_to_element(img_driver).perform() webdriver.implicitly_wait(4) fans_info = FansInfo() fans_info_driver = webdriver.find_element_by_class_name('layer_personcard') fans_nums_info_driver = fans_info_driver.find_element_by_class_name('c_count').find_elements_by_tag_name('em') print fans_nums_info_driver[0].text.encode('utf-8').strip() fans_info.focus_num = int(fans_nums_info_driver[0].text.encode('utf-8').strip()) fans_info.fans_num = fans_nums_info_driver[1].text.encode('utf-8') if '万' in fans_info.fans_num: fans_info.fans_num = int(fans_info.fans_num.strip()[:-3] + '0000') else: fans_info.fans_num = int(fans_info.fans_num.strip()) fans_info.weibo_num = int(fans_nums_info_driver[2].text.encode('utf-8').strip()) fans_info.name = fans_info_driver.find_element_by_class_name('W_f14').get_attribute('title').encode('utf-8') fans_info.gender = fans_info_driver.find_element_by_tag_name('em').get_attribute('title').encode('utf-8') return fans_info
def show_fans_info(weibo_driver, webdriver): img_driver = weibo_driver.find_element_by_xpath( ".//div[@class='WB_face W_fl']").find_element_by_tag_name('img') ActionChains(webdriver).move_to_element(img_driver).perform() webdriver.implicitly_wait(4) fans_info = FansInfo() fans_info_driver = webdriver.find_element_by_class_name('layer_personcard') fans_nums_info_driver = fans_info_driver.find_element_by_class_name( 'c_count').find_elements_by_tag_name('em') print fans_nums_info_driver[0].text.encode('utf-8').strip() fans_info.focus_num = int( fans_nums_info_driver[0].text.encode('utf-8').strip()) fans_info.fans_num = fans_nums_info_driver[1].text.encode('utf-8') if '万' in fans_info.fans_num: fans_info.fans_num = int(fans_info.fans_num.strip()[:-3] + '0000') else: fans_info.fans_num = int(fans_info.fans_num.strip()) fans_info.weibo_num = int( fans_nums_info_driver[2].text.encode('utf-8').strip()) fans_info.name = fans_info_driver.find_element_by_class_name( 'W_f14').get_attribute('title').encode('utf-8') fans_info.gender = fans_info_driver.find_element_by_tag_name( 'em').get_attribute('title').encode('utf-8') return fans_info