def getCourseList(self): url = "%sgetCourseList" % config.API_ADDRESS; get_course_list = InGetCourseList(config.API_KEY, config.CATEGORY_ID, 'GS011', SORT); data = ConvertObj.convert_to_dict(get_course_list); interface_result = HttpRequest.requestInterface(url, data); assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回code错误" object = interface_result.error_reason; for course in object['data']: print(course['name']); print(course['id']); assert course['id'] is not None, "id 不能为空"; assert course['name'] is not None, "课程名称不能为空"; assert course['name_us'] is not None, "课程英文名称 不能为空"; assert course['organ_id'] is not None, "组织机构ID 不能为空"; assert course['organ_name'] is not None, "组织机构名称 不能为空"; assert course['subject_id'] is not None, "科目ID 不能为空"; assert course['subject_name'] is not None, "科目名称 不能为空"; assert course['watch_count'] is not None, "观看数量 不能为空"; assert course['favor_count'] is not None, "收藏数量 不能为空"; assert course['img_url'] is not None, "图片地址 不能为空"; from util.UtilMethod import get_url_isexist img_url_http_code = get_url_isexist(course['img_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "图片地址不存在"; assert course['type'] is not None, "课程类型类型不能为空(课程类型1-普通课程,2-专题课程"; return object;
def getCoursewareInfo(self): url = "%sgetCoursewareInfo" % config.API_ADDRESS favorTheme = InGetCoursewareInfo(config.API_KEY, config.USER_ID, "HSNVC326", 'HSNCV7489', 8, 0, 1, 1, 1) data = ConvertObj.convert_to_dict(favorTheme) try: interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for object_info in object['data']: assert object_info['fhd_url'] is not None, "fhd_url地址不能为空" assert object_info['hd_url'] is not None, "hd_url地址不能为空" assert object_info['sd_url'] is not None, "sd_url地址不能为空" assert object_info['ld_url'] is not None, "ld_url地址不能为空" assert object_info['id'] is not None, "id地址不能为空" img_url_http_code = get_url_isexist(object_info['fhd_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "fhd_url地址不存在" img_url_http_code = get_url_isexist(object_info['hd_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "hd_url地址不存在" img_url_http_code = get_url_isexist(object_info['sd_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "sd_url地址不存在" img_url_http_code = get_url_isexist(object_info['ld_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "ld_url地址不存在" except Exception as e: print(Exception, "----Exception-------------------:", e)
def getCourseInfo(self): url = "%sgetCourseInfo" % config.API_ADDRESS; favorTheme = InGetCourseInfo(config.API_KEY, config.USER_ID, 'HSNVC1281'); data = ConvertObj.convert_to_dict(favorTheme); interface_result = HttpRequest.requestInterface(url, data); assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason; for object_info in object['data']: assert object_info['id'] is not None, "ID不能为空"; print(object_info['name']); assert object_info['share_url'] is not None, "分享的Url不能为空"; from util.UtilMethod import get_url_isexist share_url_http_code = get_url_isexist(object_info['share_url']) assert share_url_http_code == config.URL_SUCCESS_CODE, "分享的地址不存在"; assert object_info['subject_name'] is not None, "科目名称不能为空"; assert object_info['subject_id'] is not None, "科目ID不能为空"; assert object_info['category_id'] is not None, "分类ID不能为空"; assert object_info['category_name'] is not None, "分类名称不能为空"; assert object_info['praise_count'] is not None, "praise_count不能为空"; assert object_info['watch_count'] is not None, "watch_count不能为空"; assert object_info['organ_name'] is not None, "organ_name不能为空"; assert object_info['img_url'] is not None, "img_url不能为空"; assert object_info['organ_id'] is not None, "organ_id不能为空"; assert object_info['name'] is not None, "name不能为空"; assert object_info['name_us'] is not None, "name_us不能为空"; assert object_info['summary'] is not None, "summary不能为空"; assert object_info['img_url'] is not None, "img_url不能为空"; img_url_http_code = get_url_isexist(object_info['img_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "课程图片地址不存在";
def getResponse(host, movie_url): global number _proxy = getProxy() response = HttpRequest.httpRequest(host, url=movie_url, proxy=_proxy) number += 1 if not response._request: getResponse(host, movie_url) else: return response
def favorTheme(): url = "%sfavorTheme" % config.API_ADDRESS print(url) relativeTheme = InFavorTheme(config.API_KEY, config.USER_ID, 'TH107') data = ConvertObj.convert_to_dict(relativeTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason assert object['code'] == config.INTERFACE_SUCCESS_CODE, "收藏专题失败"
def afterWatchCourse(self): url = "%safterWatchCourse" % config.API_ADDRESS favorTheme = InAfterWatchCourse(config.API_KEY, 10599667, 'HSNVC326', 'HSNCV7489', 8, 0, 1, 1, 'DBA30104150100260') data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason assert object['code'] is not None, "上报观看行为失败"
def test_praiseCourse(self): url = "%spraiseCourse" % config.API_ADDRESS favorTheme = InPraiseCourse(config.IDS, config.USER_ID, config.REGISTER_ID, config.API_KEY) data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for object_info in object['data']: assert object_info['count'] is not None, "点赞数量没有增加"
def getCourseCount(self): url = "%sgetCourseCount" % config.API_ADDRESS; favorTheme = InGetCourseCount(config.API_KEY, config.USER_ID, 1); data = ConvertObj.convert_to_dict(favorTheme); get_Favor_Theme_List = HttpRequest.requestInterface(url, data); assert get_Favor_Theme_List['code'] == config.INTERFACE_SUCCESS_CODE, "接口返回码错误"; print(get_Favor_Theme_List['msg']);
def getFilterConditionList(self): url = "%sgetFilterConditionList" % config.API_ADDRESS; favorTheme = InGetFilterConditionList(config.API_KEY, 'HSNVC326', config.USER_ID, 1); data = ConvertObj.convert_to_dict(favorTheme); get_Favor_Theme_List = HttpRequest.requestInterface(url, data); print(get_Favor_Theme_List); print(get_Favor_Theme_List['code']); print(get_Favor_Theme_List['msg']);
def getThemeCourseList(self): url = "%sgetThemeCourseList" % config.API_ADDRESS; favorTheme = InGetThemeCourseList(config.API_KEY, 'TH113'); data = ConvertObj.convert_to_dict(favorTheme); interface_result = HttpRequest.requestInterface(url, data); assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason; assert object['code'] == config.INTERFACE_SUCCESS_CODE, "获取专题的课程列表失败";
def getHomeRecommend(): url = "%sgetHomeRecommend" % config.API_ADDRESS favorTheme = InGetHomeRecommend(config.API_KEY, PROJECT_TYPE, config.USER_ID) # 将对象转成字典 data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason assert object['code'] == config.INTERFACE_SUCCESS_CODE, "获取相关专题失败" for favorTheme in object['data']: check_banner_url_is_exist(favorTheme) # 判断banner地址是否存在
def clearWatchHistory(self): url = "%sclearWatchHistory" % config.API_ADDRESS favorTheme = InClearWatchHistory(config.API_KEY, 10599667) data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) try: assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason assert object[ "code"] == config.INTERFACE_SUCCESS_CODE, "清空观看历史,清除失败" except Exception as e: print(Exception, "---------------Exception----------:", e)
def getThemeList(): url = "%sgetThemeList" % config.API_ADDRESS themeInfo = InGetThemeList(config.API_KEY, 0, 20) data = ConvertObj.convert_to_dict(themeInfo) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for theme in object['data']: assert theme['id'] is not None, "id 不能为空" assert theme['img_url'] is not None, "img_url 不能为空" assert theme['name'] is not None, "专题名称 不能为空" img_url_http_code = get_url_isexist(theme['img_url']) assert img_url_http_code == config.URL_SUCCESS_CODE, "缩略图片地址不存在"
def getFavorThemeList(): url = "%sgetFavorThemeList" % config.API_ADDRESS favorTheme = InGetFavorThemeList(config.API_KEY, config.USER_ID, 0, 36, 'DMA31105150914191') data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for object_info in object['data']: assert object_info['id'] is not None, "id不能为空" assert object_info['img_url'] is not None, "图片Url不能为空" assert object_info['name'] is not None, "专题图片不能为空" url = object_info['img_url'] img_url_http_code = get_url_isexist(url) assert img_url_http_code == config.URL_SUCCESS_CODE, "图片地址不存在"
def getLearnedCourseList(self): url = "%sgetLearnedCourseList" % config.API_ADDRESS; favorTheme = InGetLearnedCourseList(config.API_KEY, 'TH113', 10265093, 0, 0, 10000); data = ConvertObj.convert_to_dict(favorTheme); interface_result = HttpRequest.requestInterface(url, data); assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误"; object = interface_result.error_reason; for object_info in object['data']: assert object_info['id'] is not None, "id不能为空"; assert object_info['name'] is not None, "name 不能为空"; assert object_info['name_us'] is not None, "name_us 不能为空"; assert object_info['img_url'] is not None, "img_url 不能为空"; assert object_info['courseware_total_count'] is not None, "课件总数量不正常"; assert object_info['courseware_finished_count'] is not None, "courseware_finished_count 不能为空"; assert object_info['courseware_total_count'] is not None, "课件总数量不正常"; assert object_info['type'] is not None, "type不能为空";
def getThemeInfo(): url = "%sgetThemeInfo" % config.API_ADDRESS themeInfo = InGetThemeInfo(config.API_KEY, config.USER_ID, 'TH314') data = ConvertObj.convert_to_dict(themeInfo) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for object_info in object['data']: assert object_info['name'] is not None, "专题名称不能为空" assert object_info['background_img_url'] is not None, "背景图片不能为空" assert object_info['img_url'] is not None, "缩略图片不能为空" background_http_code = get_url_isexist( object_info['background_img_url']) assert background_http_code == config.URL_SUCCESS_CODE, "背景图片地址不存在" background_http_code = get_url_isexist(object_info['img_url']) assert background_http_code == config.URL_SUCCESS_CODE, "缩略图片地址不存在"
def getCoursewareList(self): url = "%sgetCoursewareList" % config.API_ADDRESS course_list = InGetCoursewareList(config.API_KEY, 'HSNVC1272', 10599667, 0, 0, 10000) data = ConvertObj.convert_to_dict(course_list) interface_result = HttpRequest.requestInterface(url, data) try: assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason for data_info in object['data']: print(data_info['name']) assert data_info['name'] is not None, "课件名称不能为空" # assert data_info['name_us'] is not None, "课件英文名称不能为空"; assert data_info['id'] is not None, "课件ID不能为空" except Exception as e: print(Exception, ":------getCoursewareList---------------", e)
def test_favorCourse(self): url = "%sfavorCourse" % config.API_ADDRESS favorTheme = InFavorCourse(config.IDS, config.USER_ID, config.API_KEY) data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason assert object['code'] == config.INTERFACE_SUCCESS_CODE, "接口返回码错误" for object_info in object['data']: assert object_info['count'] is not None, "攒点数量有误" # 查看收藏的课程 object = CourseRelative.getFavorCourseList(self) for favorTheme in object['data']: # print(favorTheme['id']); if config.IDS == favorTheme['id']: print("------true-------------")
def test_remove_user_collection(self): url = "%sremoveUserFavorCourse/%s/%s/%s" % ( config.API_ADDRESS, config.CATEGORY_TYPE, config.TYPE, config.IDS) inputParam = InRemoveUserFavorCourse(config.API_KEY, config.USER_ID) data = ConvertObj.convert_to_dict(inputParam) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回码错误" object = interface_result.error_reason code = object['code'] print(code) assert code == config.INTERFACE_SUCCESS_CODE, "清除用户历史记录失败" print("----------------------------------") object = CourseRelative.getFavorCourseList(self) for favorTheme in object['data']: # print(favorTheme['id']); if config.IDS == favorTheme['id']: print("------false-------------")
def getWatchHistory(self): url = "%sgetWatchHistory" % config.API_ADDRESS favorTheme = InGetWatchHistory(config.API_KEY, 10599667) # 将对象转成字典 data = ConvertObj.convert_to_dict(favorTheme) interface_result = HttpRequest.requestInterface(url, data) assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口请求失败" object = interface_result.error_reason for favorTheme in object['data']: assert favorTheme['id'] is not None, "id不能为空" assert favorTheme['courseware_id'] is not None, "课件id不能为空" assert favorTheme['name'] is not None, "课程名称不能为空" assert favorTheme['name_us'] is not None, "课程英文名称不能为空" assert favorTheme['img_url'] is not None, "图片地址不能为空" assert favorTheme['courseware_name'] is not None, "课件名称不能为空" assert favorTheme['type'] is not None, "类型不能为空" assert favorTheme['view_type'] is not None, "view_type不能为空" assert favorTheme['status'] is not None, "状态不能为空"
def getCategorySubjects(self,category_id): url = "%sgetCategorySubjects" % config.API_ADDRESS; favorTheme = InGetCategorySubjects(config.API_KEY, config.USER_ID, category_id); from util import ConvertObj data = ConvertObj.convert_to_dict(favorTheme); from util import HttpRequest interface_result = HttpRequest.requestInterface(url, data); try: assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口请求失败"; object = interface_result.error_reason; assert object['code'] == config.INTERFACE_SUCCESS_CODE, "接口返回码不正确"; for favorTheme in object['data']: assert favorTheme["id"] is not None, "id 不能为空"; assert favorTheme["name"] is not None, "科目名称不能为空"; print(favorTheme['id']); print(favorTheme['name']); return object; except Exception as e: print(Exception, e);
def getCourseCategories(self): url = "%sgetCourseCategories" % config.API_ADDRESS; object_vo = InGetCourseCategories(config.API_KEY); data = ConvertObj.convert_to_dict(object_vo); interface_result = HttpRequest.requestInterface(url, data); try: if interface_result.result_status == config.INTERFACE_SUCCESS_STATUS: object = interface_result.error_reason; for obj_detail in object['data']: img_url = obj_detail['img_url']; assert obj_detail['id'] is not None, "id不能为空"; assert obj_detail['name'] is not None, "name不能为空"; assert obj_detail['sort'] is not None, "排序不能为空"; assert obj_detail['img_url'] is not None, "分类图片不能为空"; img_url_http_code = get_url_isexist(img_url) assert img_url_http_code == config.URL_SUCCESS_CODE, "分类图片地址不存在"; except Exception as e: print(Exception, e);
Created on PyCharm @author: Edison @date: 15/8/6 下午4:31 @summary: @note: @version: ''' __author__ = 'Edison' import os,sys import spider_movie from util import HttpRequest from bs4 import BeautifulSoup reload(sys) sys.setdefaultencoding('utf8') host = "rrmj.tv" response = HttpRequest.httpRequest(host) html_code = BeautifulSoup(response.response()) for i in html_code.select("#menu3"): print i.href
<p class="tt cl"> <span>2015/07/31</span> <a href="/subject/26978.html" target="_blank"> <b> <font color="#FF6600">小时代4:灵魂尽头迅雷下载<i>/小时代4:灵魂尽头</i>.2015</font> </b> </a> </p> <p>又名:<a href="/subject/26978.html" target="_blank">小时代4/Tiny Time 4.0</a></p> <p class="des">2015(中国大陆)<em>/</em>杨幂<em>/</em>郭采洁<em>/</em>陈学冬<em>/</em>郭碧婷<em>/</em>谢依霖<em>/</em>李贤宰<em>/</em>锦荣<em>/</em>任言恺<em>/</em>姜潮<em>/</em>王琳<em>/</em>商侃<em>/</em>郭敬明</p> <p class="rt">豆瓣评分:<strong>4</strong><em class="dian">.</em><em class="fm">7</em> <a href="/jumpto.php?aid=26978" rel="nofollow" target="_blank" title="去豆瓣查看影片介绍"><em class="e_db"></em></a></p> ''' reload(sys) sys.setdefaultencoding('utf8') host = "www.bttiantang.com" for p in range(1, 687): response = HttpRequest.httpRequest(host, url="http://"+host+"/?PageNo="+str(p)) html_code = BeautifulSoup(response.response().text) for i in html_code.find_all('div', class_="item"): for j in i.select(".title > .tt"): try: http_path = "http://"+host+j.a['href'] spider_movie.SpiderMovies.delay(host, str(http_path)) except Exception, e: print e,j
def getFavorCourseList(self): url = "%sgetFavorCourseList" % config.API_ADDRESS; favorTheme = InGetFavorCourseList(config.USER_ID, config.API_KEY, 0, 10); from util import ConvertObj data = ConvertObj.convert_to_dict(favorTheme); # get_Favor_Theme_List = HttpRequest.requestInterface(url, data); from util import HttpRequest interface_result = HttpRequest.requestInterface(url, data); assert interface_result.result_status == config.INTERFACE_SUCCESS_STATUS, "接口返回code错误" object = interface_result.error_reason; for favorTheme in object['data']: print(favorTheme['id']); print(favorTheme['name']); assert favorTheme['id'] is not None, "ID不能为空"; assert favorTheme['subject_name'] is not None, "科目名称不能为空"; assert favorTheme['subject_id'] is not None, "科目ID不能为空"; assert favorTheme['category_id'] is not None, "分类ID不能为空"; assert favorTheme['category_name'] is not None, "分类名称不能为空"; assert favorTheme['organ_name'] is not None, "组织机构的ID不能为空"; assert favorTheme['img_url'] is not None, "组织机构的ID不能为空"; assert favorTheme['name'] is not None, "课程名称不能为空"; assert favorTheme['summary'] is not None, "备注不能为空"; return object; # print(favorTheme['condition_id']); # print(favorTheme['condition_name']); # print(favorTheme['label_id']); # print(favorTheme['label_name']); # print(favorTheme['praise_count']); # print(favorTheme['is_favor']); # print(favorTheme['is_praised']); # print(favorTheme['watch_count']); # print(favorTheme['speaker_id']); # print(favorTheme['speaker_name']); # print(favorTheme['img_url_us']); # print(favorTheme['type']); # print(favorTheme['uniq_id']); # print(favorTheme['organ_id']); # print(favorTheme['name']); # print(favorTheme['name_us']); # print(favorTheme['summary']); # print(favorTheme['status']); # print(favorTheme['update_status']); # 获取课程分类列表 def getFilterConditionList(self): url = "%sgetFilterConditionList" % config.API_ADDRESS; favorTheme = InGetFilterConditionList(config.API_KEY, 'HSNVC326', config.USER_ID, 1); data = ConvertObj.convert_to_dict(favorTheme); get_Favor_Theme_List = HttpRequest.requestInterface(url, data); print(get_Favor_Theme_List); print(get_Favor_Theme_List['code']); print(get_Favor_Theme_List['msg']);
import os, sys from util import HttpRequest from util import Configs from util import MysqlClient from bs4 import BeautifulSoup reload(sys) sys.setdefaultencoding('utf8') config = Configs.Configs() db = MysqlClient.MysqlDB() request = HttpRequest.httpRequest("cn-proxy.com", "http://cn-proxy.com") html_code = BeautifulSoup(request.response().text) def saveDb(sqls): return db.execute(sqls) def queryDb(sqls): return db.queryFirst(sqls) for tables in html_code.find_all('table', class_="sortable"): for trs in tables.find_all('tr'): tds = [] n = 0 for td in trs.select("td"): try: