예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
0
 def article_detail_info(self):
     item = pq(self.txt)('.article-text-box')
     title = item('h1').text()  # 文章标题
     ava_img = item('img').attr('src').split('uploads/')[-1]  # 发布人头像图片
     ava_link = item('.u-photo-btn').attr('href').split('/')[-1]  # 发布人动态链接
     nick_name = item('.u-name').text()  # 发布人昵称
     date_publish = item('.u-datetime').text()  # 发布时间
     tags = item('.hot-tag-group').text()  # 文章标签
     content = item('#article').text().replace('\n', '').replace(' ',
                                                                 '')  # 文章内容
     forward_count = item('.col-right span').eq(2).text()  # 点赞数
     collect_count = item('.col-right #whole_article').text().split()[
         -1]  # 收藏数
     review_count = item('.col-right .u-view').text().split()[-1]  # 浏览数
     actual = list()
     actual.append((title, ava_img, ava_link, nick_name, date_publish, tags,
                    content, forward_count, collect_count, review_count))
     expect = select(
         sqls.articel_detail_info.replace('lilang_type', self.article_id))
     expect = list(expect)
     for i in range(len(expect)):
         expect[i] = list(expect[i])
         expect[i][5] = expect[i][5].replace(',',
                                             '') if expect[i][5] else ''
         expect[i][6] = pq(content_deal(expect[i][6])).text().replace(
             ' ', '')
     equal('article_detail_info', expect, actual)
예제 #5
0
 def ask_hot_tags(self):
     item = self.txt('.hot-tag-box .hot-tag')
     actual = list()
     for i in item:
         i = pq(i)
         actual.append((i.text(), ))  # 标签集合
     expect = select(sqls.ask_hot_tags)
     equal('ask_hot_tags', expect, actual)
예제 #6
0
 def ask_rule(self):
     item = self.txt('.main-area-right .ibox-body>.notice-information')
     rule = pq(item).text()  # 规则集合
     actual = list()
     actual.append((rule, ))
     expect = list()
     expect.append((sqls.ask_rule, ))
     equal('ask_rule', expect, actual)
예제 #7
0
 def ask_total_count(self):
     item = self.txt('.zypage')
     page = pq(item)('#page-pane2').text()  # 总页数
     lp = pq(requests.get(self.url + '?page=' + page).text)
     last_count = len(lp('.QA-list>.item'))
     total_count = int(page) * 20 + last_count - 20
     actual = list()
     actual.append((total_count, ))
     expect = select(sqls.ask_count)
     equal('ask_total_count', expect, actual)
예제 #8
0
 def ask_detail_hot_tags(self):
     driver = self.driver
     item = driver.find_element_by_class_name(
         'hot-tag-boxin').find_elements_by_class_name('hot-tag')
     actual = list()
     for i in item:
         tag = i.text
         actual.append((tag, ))
     expect = select(sqls.ask_hot_tags)
     equal('ask_detail_hot_tags', expect, actual)
     driver.close()
예제 #9
0
 def ask_hot_qa(self):
     item = self.txt('#hotQA .item')
     actual = list()
     for i in item:
         i = pq(i)
         link = i('a').attr('href').split('/')[-1]  # 问答链接
         count = i('a>span').text().split()[0]  # 回答数量
         title = i('a').remove('span').text()  # 问答标题
         actual.append((link, title, count))
     self.driver.close()
     expect = select(sqls.ask_hot_qa)
     equal('ask_hot_qa', expect, actual)
예제 #10
0
 def submit_consult_info(self):
     name = '李朗' + str(random.randint(0, 100))  # 随机姓名
     phone = 18000000000 + random.randint(0, 1000000000)  # 随机手机号
     url = self.url + 'v3/submitConsultInfo/?realName=' + name + '&phoneNum=' + str(
         phone)
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     message = txt['message']  # 返回信息
     actual.append((message, name, phone))
     expect = select(sqls.submit_consult_info)
     equal('submit_consult_info', expect, actual)
예제 #11
0
 def get_excellent_recom(self):
     url = self.url + 'v3/getExcellentRecom/?UUID=&userId='
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     for i in txt['data']['list']:
         course_id = i['course_id']  # 推荐课程id
         img_url = i['img_url'].split('uploads/')[-1]  # 课程图片
         name = i['name']  # 课程名称
         actual.append((course_id, img_url, name))
     expect = select(sqls.get_excellent_recom)
     equal('get_excellent_recom', expect, actual)
예제 #12
0
 def article_detail_relate(self):
     item = pq(self.txt)('.hot-article-list>.item')
     actual = list()
     for i in item:
         i = pq(i)
         link = i('a').attr('href').split('/')[-1]  # 链接
         title = i.text()  # 标题
         actual.append((link, title))
     actual = actual if actual else ['无相关问答']
     expect = select(
         sqls.article_detail_relate.replace('lilang_id', self.article_id))
     expect = expect if expect else ['无相关问答']
     equal('article_detail_relate', expect, actual)
예제 #13
0
 def talk_page(self):
     actual = Article().article_page(self.talk_url)
     total = select(sqls.article_total_count.replace('lilang_type', '5'))
     if total[0][0] % 10 > 0:
         count = total[0][0] / 10 + 1
     else:
         count = total[0][0] / 10
     expect = list()
     if count > 1:
         expect.append((count, '1', '2', '1'))
     else:
         expect.append(('1', ))
     equal('talk_page', expect, actual)
예제 #14
0
 def ask_publish(self):
     driver = self.driver
     driver.find_element_by_xpath(
         '/html/body/div[7]/div[3]/div/div/div[2]/div[1]/a').click()
     time.sleep(4)
     actual = list()
     txt = driver.find_element_by_class_name(
         'good-tips').find_element_by_tag_name('a').text
     actual.append((txt, ))
     driver.close()
     expect = list()
     expect.append(('忘记密码?', ))
     equal('ask_publish', expect, actual)
예제 #15
0
 def task__list_schedule(self):
     ses = login_by_res('18008062322', '11111111')
     txt = pq(ses.get(self.url).text)
     actual = list()
     for i in txt('#lineList>ul>li'):
         i = pq(i)
         stage_name = i('.zyStageTit').text()
         for j in i('.YaHei'):
             j = pq(j)
             task_name = j.text()
             actual.append((stage_name, task_name))
     expect = select(sqls.task_list)
     equal('task_list', expect, actual)
예제 #16
0
 def get_excellent_course_ad(self):
     url = self.url + 'v3/getExcellentCourse/?orderBy=2&loadAd=1'
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     for i in txt['data']['ad']:
         img = i['url'].split('uploads/')[-1]  # 广告图片
         callback_url = i['out_url']  # 广告回调url
         target_id = i['target_id']  # 目标id,不晓得有毛用
         ad_type = i['ad_type']  # 广告类型
         title = i['name']  # 广告标题
         actual.append((img, callback_url, target_id, ad_type, title))
     expect = select(sqls.get_excellent_course_ad)
     equal('get_excellent_course_ad', expect, actual)
예제 #17
0
 def ask_detail_relate_course_ask(self):
     actual = list()
     item = self.txt('.hot-QA-list>.item')
     for i in item:
         i = pq(i)
         link = i('a').attr('href').split('/')[-1]  # 问答链接
         count = i('a>span').text().split()[0]  # 回答数量
         title = i('a').remove('span').text()  # 问答标题
         actual.append((link, title, count))
     actual = actual if actual else ['无相关问答']
     expect = select(
         sqls.ask_detail_relate_course_ask.replace('lilang_id',
                                                   self.ask_id))
     expect = expect if expect else ['无相关问答']
     equal('ask_detail_relate_course_ask', expect, actual)
예제 #18
0
 def get_career_course(self):
     url = self.url + 'v3/getCareerCourse/?count=0'
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     for i in txt['data']['list']:
         course_count = i['course_count']  # 课程数量
         student_count = i['student_count']  # 学生数量
         name = i['name']  # 直通班课程名
         class_count = i['class_count']  # 开班数量
         career_id = i['career_id']  # 课程id
         img_url = i['img_url'].split('uploads/')[-1]  # 课程图片
         actual.append((course_count, student_count, name, class_count,
                        career_id, img_url))
     expect = select(sqls.get_career_course)
     equal('get_career_course', expect, actual)
예제 #19
0
 def get_excellent_course(self):
     url = self.url + 'v3/getExcellentCourse/?orderBy=2&loadAd=0'
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     for i in txt['data']['list']:
         click_count = i['student_count']  # 课程点击次数
         lesson_count = i['lesson_count']  # 课程视频个数
         course_id = i['course_id']  # 课程id
         name = i['course_name']  # 课程名称
         img = i['img_url'].split('uploads/')[-1]  # 课程图片链接
         teacher = i['teacher']  # 教师昵称
         updating = i['updating']  # 是否更新中,0为不更新
         actual.append((click_count, lesson_count, course_id, name, img,
                        teacher, updating))
     expect = select(sqls.get_excellent_course)
     equal('get_excellent_course', expect, actual)
예제 #20
0
 def get_career_detail(self, career_id):
     url = self.url + 'v3/getCareerDetail/?careerId=' + career_id + '&UUID=a489516c4e73436bbbeb1a695940fdcf&userId=108'
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     course_desc = txt['data']['desc']  # 职业课程介绍
     index_html = txt['data']['index_html']  # 职业课程落地页地址
     for i in txt['data']['stage']:
         stage_desc = i['stage_desc']  # 阶段描述
         stage_id = i['stage_id']  # 阶段id
         stage_name = i['stage_name']  # 阶段名称
         for j in i['list']:
             course_id = j['course_id']  # 课程id
             img_url = j['img_url'].split('uploads/')[-1]  # 课程图片
             name = j['name']  # 课程名称
             updating = j['updating']  # 是否更新中
             actual.append((course_desc, index_html, stage_desc, stage_id,
                            stage_name, course_id, img_url, name, updating))
     expect = select(sqls.get_career_detail.replace('my_id', career_id))
     equal('get_career_detail', expect, actual)
예제 #21
0
 def ask_rank(self):
     driver = self.driver
     lists = driver.find_element_by_xpath(
         '/html/body/div[7]/div[3]/div/div/div[2]/div[6]')
     item = lists.find_elements_by_tag_name('li')
     actual = list()
     for i in item:
         link = i.find_element_by_tag_name('a').get_attribute('href').split(
             '/')[-1]  # 用户链接
         ava = i.find_element_by_tag_name('img').get_attribute('src').split(
             'http://192.168.1.142//uploads/')[-1]
         nick_name = i.find_element_by_class_name('a1').text  # 昵称
         desc = i.find_element_by_class_name('a2').text  # 用户介绍
         count = i.find_element_by_class_name(
             'huoBox_ul_font2').text.split()[0]  # 回答数量
         actual.append((link, ava, nick_name, desc, count))
     driver.close()
     expect = select(sqls.ask_rank)
     expect = expect if expect else ['无数据']
     equal('ask_rank', expect, actual)
예제 #22
0
 def get_career_price(self, career_id):
     url = self.url + 'v3/getCareerPrice/?careerId=' + career_id + '&UUID=a489516c4e73436bbbeb1a695940fdcf&userId=108'
     res = requests.get(url)
     txt = json.loads(res.text)
     actual = list()
     first_pay = txt['data']['pay']['first_pay']  # 首付价格
     price = txt['data']['pay']['price']  # 全款价格
     for i in txt['data']['class_list']:
         class_id = i['class_id']  # 班级ID
         curr_student = i['curr_student']  # 当前报名人数
         teacher = i['teacher']  # 教师昵称,麻痹取不到接口要挂
         class_no = i['class_no']  # 班级coding
         max_student = i['max_student']  # 报名上限人数
         actual.append((
             first_pay,
             price,
             class_id,
             curr_student,
             teacher,
             class_no,
             max_student,
         ))
     expect = select(sqls.get_career_price.replace('my_id', career_id))
     equal('get_career_price', expect, actual)
예제 #23
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)
예제 #24
0
 def news_hot_news(self):
     actual = Article().article_hot_article(self.news_url)
     expect = select(sqls.article_hot_article)
     equal('news_hot_news', expect, actual)
예제 #25
0
 def cafe_hot_cafe(self):
     actual = Article().article_hot_article(self.cafe_url)
     expect = select(sqls.article_hot_article)
     equal('cafe_hot_cafe', expect, actual)
예제 #26
0
 def talk_hot_talk(self):
     actual = Article().article_hot_article(self.talk_url)
     expect = select(sqls.article_hot_article)
     equal('talk_hot_talk', expect, actual)
예제 #27
0
 def news_publish(self):
     actual = Article().article_publish(self.news_url)
     expect = list()
     expect.append(('登录', ))
     equal('news_publish', expect, actual)
예제 #28
0
 def cafe_publish(self):
     actual = Article().article_publish(self.cafe_url)
     expect = list()
     expect.append(('登录', ))
     equal('cafe_publish', expect, actual)
예제 #29
0
 def talk_publish(self):
     actual = Article().article_publish(self.talk_url)
     expect = list()
     expect.append(('登录', ))
     equal('talk_publish', expect, actual)
예제 #30
0
 def class_hot_class(self):
     actual = Article().article_hot_article(self.class_url)
     expect = select(sqls.article_hot_article)
     equal('class_hot_class', expect, actual)