Exemple #1
0
 def ask_detail_discuss(self):
     driver = self.driver
     item = driver.find_element_by_id(
         'comments').find_elements_by_class_name('item')
     time.sleep(3)
     actual = list()
     for i in item:
         if i.text != '':  # 这里标签有重复,去除哪些没得内容的,不要坑我
             ava = i.find_element_by_tag_name('a').get_attribute(
                 'href').split('dynmsg/')[-1]  # 动态链接
             nick_name = i.find_element_by_class_name('u-name').text  # 昵称
             date_publish = i.find_element_by_class_name(
                 'u-datetime').text  # 发布日期
             content = i.find_element_by_class_name(
                 'zy_shou11').text.replace(' ', '')  # 发布内容
             count = i.find_element_by_class_name(
                 'icon-label-text').text  # 点赞数
             actual.append((ava, nick_name, date_publish, content, count))
     driver.close()
     expect = select(sqls.ask_discuss.replace('lilang_id', self.ask_id))
     expect = list(expect)
     for i in range(len(expect)):
         expect[i] = list(expect[i])
         expect[i][2] = time_deal(expect[i][2])
         expect[i][3] = pq(content_deal(expect[i][3])).text().replace(
             ' ', '')
     actual = actual if actual else ['null']
     expect = expect if expect else ['null']
     equal('ask_detail_discuss', expect, actual)
Exemple #2
0
 def ask_detail_base_info(self):
     driver = self.driver
     actual = list()
     main = driver.find_element_by_class_name('QA-text-box')  # 获取详情主体框
     title = main.find_element_by_tag_name('h1').text  # 问答标题
     content = main.find_element_by_class_name('QA-text-main').text  # 问答内容
     tags = main.find_element_by_class_name('hot-tag-group').text  # 问答标签
     nick_name = main.find_element_by_class_name('u-name').text  # 发布人昵称
     publish_date = main.find_element_by_class_name(
         'u-datetime').text  # 发布日期
     forward_count = main.find_element_by_class_name(
         'praise-btn').text.split()[-1]  # 点赞数
     collect_count = main.find_element_by_class_name(
         'u-collect').text.split()[-1]  # 收藏数
     review_count = main.find_element_by_class_name('u-view').text.split()[
         -1]  # 浏览数
     time.sleep(3)
     driver.close()
     actual.append((title, content, tags, nick_name, publish_date,
                    forward_count, collect_count, review_count))
     expect = select(
         sqls.ask_detail_base_info.replace('lilang_id', self.ask_id))
     expect = list(expect)
     for i in range(len(expect)):
         expect[i] = list(expect[i])
         expect[i][1] = pq(content_deal(expect[i][1])).text()
         expect[i][2] = expect[i][2].replace(',', ' ')
         expect[i][4] = time_deal(expect[i][4])
         expect[i][7] -= 1
     equal('ask_detail_base_info', expect, actual)
Exemple #3
0
 def ask_detail_course_ask_base_info(self):
     driver = self.driver
     actual = list()
     main = driver.find_element_by_class_name('QA-text-box')  # 获取详情主体框
     title = main.find_element_by_tag_name('h1').text  # 问答标题
     content = main.find_element_by_class_name('QA-text-main').text.replace(
         '\n', '').replace(' ', '')  # 问答内容
     tags = main.find_element_by_class_name('hot-tag-group').text  # 问答标签
     source = main.find_element_by_class_name('art_zy_edit').text.split(
         '源自:')[-1]  # 源自
     nick_name = main.find_element_by_class_name('u-name').text  # 发布人昵称
     publish_date = main.find_element_by_class_name(
         'u-datetime').text  # 发布日期
     forward_count = main.find_element_by_xpath(
         '/html/body/div[9]/div[5]/div/div/div[1]/div/'
         'div[1]/div[3]/div[2]/span[2]').text  # 点赞数
     collect_count = main.find_element_by_class_name(
         'u-collect').text.split()[-1]  # 收藏数
     review_count = main.find_element_by_class_name('u-view').text.split()[
         -1]  # 浏览数
     time.sleep(3)
     driver.close()
     actual.append((title, content, tags, source, nick_name, publish_date,
                    forward_count, collect_count, review_count))
     expect = select(
         sqls.ask_detail_course_ask_base_info.replace(
             'lilang_id', self.ask_id))
     expect = list(expect)
     for i in range(len(expect)):
         expect[i] = list(expect[i])
         expect[i][1] = pq(content_deal(expect[i][1])).text().replace(
             ' ', '')
         expect[i][5] = time_deal(expect[i][5])
         expect[i][8] -= 1
     equal('ask_detail_course_ask_base_info', expect, actual)
Exemple #4
0
 def article_list_expect(self, article_type):
     expect = select(sqls.article_list.replace('lilang_type', article_type))
     expect = list(expect)
     for i in range(len(expect)):
         expect[i] = list(expect[i])
         expect[i][2] = pq(content_deal(expect[i][2])).text()[0:49]
         expect[i][3] = pq(content_deal(expect[i][3])).text().replace(
             ' ', '').replace(u'\xa0', '')[0:80]
         expect[i][4] = expect[i][4].replace(',',
                                             '') if expect[i][4] else ''
         expect[i][8] = time_deal(expect[i][8])
     return expect
Exemple #5
0
    def ask_list(self):
        item = self.txt('.QA-list>.item')
        actual = list()
        for i in item:
            i = pq(i)
            ava = i('.col-left').find('img').attr('src').split('uploads/')[
                -1]  # 头像地址
            nick_name = i('.u-name').text()  # 昵称
            title = i('.col-right h3>a').text()  # 问答标题
            reply = i('.item-r-A').text().split('[最新回答]')[-1].replace(
                ' 查看详细', '')[0:100]  # 最新回复
            tags = i('.hot-tag-group .hot-tag').text()  # 问答标签
            tags = tags if tags else None
            source = i('.hot-tag-group .from-where').text().split('源自: ')[
                -1]  # 源自xx
            date_publish = i('.datetime').text()  # 发布时间
            review_count = i('.icon-browse').text()  # 浏览数
            reply_count = i('.icon-ask').text()  # 回复数
            forward_count = i('.icon-good').text()  # 点赞数
            actual.append(
                (ava, nick_name, title, reply, tags, source, date_publish,
                 review_count, reply_count, forward_count))
        self.driver.close()
        expect = select(sqls.ask_list)
        expect = list(expect)
        for i in range(len(expect)):
            expect[i] = list(expect[i])
            expect[i][2] = pq(content_deal(expect[i][2])).text()[0:49]
            print i, expect[i][3]
            expect[i][3] = expect[i][3] if expect[i][3] else u'还没有人回答这个问题呢...'
            expect[i][3] = pq(content_deal(expect[i][3])).text()[0:100]
            expect[i][4] = expect[i][4].replace(
                ',', '') if expect[i][4] else expect[i][4]
            expect[i][6] = time_deal(expect[i][6])

        equal('ask_list', expect, actual)