Java编程

6套慕课网算法视频教程

spider爬虫类# #-*—coding:utf8-*-import requestsimport re#下面三行是将windows控制台的编码形式转换成utf-8编码import sysreload(sys)sys.setdefaultencoding(“utf-8”)# 创建spider爬虫类class spider(object):def __init__(self):print u”开始了”# 获取每个网页的源代码def getSource(self,url):html = requests.get(url)# 将获得的源代码以utf-8的格式解析html.encoding=”utf-8″return html.text# 得到连续的多个课程网页def getPages(self,url,total):urls=[]init_page = int(re.search(“page=(\d+)”,url,re.S).group(1))for i in range(init_page,total+1):# 将页数通过正则表达式来替换link=re.sub(“page=\d+”,”page=%d”%i,url)urls.append(link)return urls# 得到每个课程页中的多个课程def getCourses(self,html):Courses=re.findall(r”

  • (.*?)
  • “,html,re.S)return Courses# 利用正则表达式筛选课程信息def getCourseInfo(self,Course):info={}# r”pattern” 匹配模式的前面加上r,就不必在转义里面的字符info[“title”]=re.search(r”(.*?)“,Course,re.S).group(1)info[“decoration”]=re.search(r”>(.*?)

    6套慕课网算法视频教程

    “,Course,re.S).group(1)# 去除字符串两边和中间的空白字符peoples=re.search(“(.*?)“,Course,re.S).group(1).strip()info[“peoples”]=re.sub(“\s+”,”,”,peoples)return info# 存储课程信息def saveAllInfo(self,allInfo):f=open(“info.txt”,”a”)for each in allInfo:f.writelines(“title:”+each[“title”]+”\n”)f.writelines(“decoration:” + each[“decoration”] + “\n”)f.writelines(“peoples:” + each[“peoples”] + “\n\n”)f.close()有些表达式,因为排版只能断开了。

    url-loader data:image/png;base64;… options:{limit:10*1024} 超过10KB使用file-loader,低于10KB使用url-loader。

    i)return sa[‘data’][‘info’] = niming(a[‘data’][‘info’])for index,c in enumerate(a[‘data’][‘encrypt_table’]):# print(index)h = a[‘data’][‘encrypt_table’][index]if (“q” == h or “k” == h):p = a[‘data’][‘key_table’].pop()a[‘data’][‘info’] = s[a[‘data’][‘encrypt_table’][index]](a[‘data’][‘info’],p)else:a[‘data’][‘info’] = s[a[‘data’][‘encrypt_table’][index]](a[‘data’][‘info’])if e:return bytes(bytearray(a[‘data’][‘info’]))g = “”for c in range(0,len(a[‘data’][‘info’])):g += chr(a[‘data’][‘info’][c])return gif __name__ == ‘__main__’:# str_ = “OqkhlImlaWFhRkh/SEIfE1FxaQgMXw9cRGU6T1xxb2BpXwx+cVkLKlw+fBxwPQBcMUNBWFxIfHRhbQxsSENHIV1UfHJtQgBHSFkfQFwqHnJhXxFcMUNYWFxIeHJtTwBBXUNQIVs9aXJsXwVcWUNQNlxeaRxfbHsXSENBISVIZQtyUwxNSE4LTUVLeFlhQy9kWCp9QFxxaXF5Xwg5SCVpLCRgYmJhNgxCHGNFaSZgWgkaXwx/a0NBAiZEVHJWXzlcc2hSZiZXcEl4Zgx+EWFYVWxJaUlhfG0ESHMFezolCB1hPTtzFCJKelxVaRcAP2JtSHMHK2oNC3ENXHdlSHJBIWF0SHIXXzlgd2VvJlxAfCFYSj17SEN4IWlkaVYIOgxcKQRmLHdgCBpuX2xIQjEubVxfWHEAZQ81dUNBIWd9UnIcXzdcL0NBOlxRanJjYBpcSE5ISjBufXdhcWx/SH18Qx5OfX9hfAEeSCVueFFgcVpfRQ9pUkplVHB6G2hiXng5SUN+TU9LdFlMX0llSF5/IVIhb05vXhBcXCRlFVxZDnIbARArSFJkQFx9ZWRzMS8eMiclRTggDQpdeUF8F2dlZCcnElB+DwxzeUNBITl/E1V5HwxzSHNfN2Fgf11aXy9Ef0N6Flw+aUttJAA9eF4FZlwNHhwFKztceF9lB1xVaRcAP2JtSHMHK2oNC3FXXHdFJDhoTVxRfwgMX0tJLCZoe1EBBHJfXzU8fWhSZiZACxw/bQxNSE9lflxUexwqMnYSLCc5RTggVSxBfyt4DWgeTSdddk9hfD1Pc0NmISYhaV9taABsclg5TWVgf19aXy9IMnRlXVxyaQlhfDweKHUFQD1gHQBWX05PSHRlCVx8aRIHTAxOKnUFJj5gf1IaRlR/fUMgFlxECHJtagA9SCMIZDBJDhVcPQA5SEM7IWxxSVVObHtzWUNBIUFIc2APPmkmSScBKREtEU4/fyx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QlhfDweKHUFQD1gHQBWX05PSHRlCVx8aRIHTAxOKnUFJj5gf1IaRlR/ekNxR2oiDnJtPjFcK0NBQD0iaRMBXy9KLUNmAVw+NwVtQgxQfmhlV15LCGIbO2k4LScBNX57SUxGeyZ8M2keb1xdfCxQSjdcLU8fZlxNaUsAbzgmdUNBIWd9UnIXXzdrSHhlH1xwaRNRXxkfSC4EblQCfXJRPg1rSXZlBFwkD0NhSm5PLi4He1xgEn13JGpcK0MmIT4paRdhSgwaSCRXTWoDBHJdX207SDlFalw+fBxwPQBcVX9DXzIBBWQFO2k4LScdE2BASVlJX2J+EThHZGFJWUNhGQxES。

    ajax({type: “POST”,url: “${pageContext.request.contextPath }/turingServlet”,data: “info=”+content,success: function(data) {}});3、着重把后台代码贴出。

    spider爬虫类# #-*—coding:utf8-*-import requestsimport re#下面三行是将windows控制台的编码形式转换成utf-8编码import sysreload(sys)sys.setdefaultencoding(“utf-8”)# 创建spider爬虫类class spider(object):def __init__(self):print u’开始了’# 获取每个网页的源代码def getSource(self,url):html = requests.get(url)# 将获得的源代码以utf-8的格式解析html.encoding=’utf-8’return html.text# 得到连续的多个课程网页def getPages(self,url,total):urls=[]init_page = int(re.search(‘page=(\d+)’,url,re.S).group(1))for i in range(init_page,total+1):# 将页数通过正则表达式来替换link=re.sub(‘page=\d+’,’page=%d’%i,url)urls.append(link)return urls# 得到每个课程页中的多个课程def getCourses(self,html):Courses=re.findall(r’

  • (.*?)
  • ‘,html,re.S)return Courses# 利用正则表达式筛选课程信息def getCourseInfo(self,Course):info={}# r”pattern” 匹配模式的前面加上r,就不必在转义里面的字符info[‘title’]=re.search(r’(.*?)‘,Course,re.S).group(1)info[‘decoration’]=re.search(r’class=”text-ellipsis”>(.*?)

    ‘,Course,re.S).group(1)# 去除字符串两边和中间的空白字符peoples=re.search(‘(.*?)‘,Course,re.S).group(1).strip()info[‘peoples’]=re.sub(‘\s+’,’,’,peoples)return info# 存储课程信息def saveAllInfo(self,allInfo):f=open(“info.txt”,’a’)for each in allInfo:f.writelines(‘title:’+each[‘title’]+’\n’)f.writelines(‘decoration:’ + each[‘decoration’] + ‘\n’)f.writelines(‘peoples:’ + each[‘peoples’] + ‘\n\n’)f.close()有些表达式,因为排版只能断开了。

    image = UIImage(data: data继续向下倒第4行,我们设置图片缓存使用这张图片的URL作为名称来保存新图片。使用URL做名称意味着在任何要显示这张图片的时候我们都可以在字典中找到它,甚至在完全不同的环境下也如此。

    “k” == h) {var p = a.data.key_table.pop();a.data.info = s[a.data.encrypt_table[c]](a.data.info, p)} else{a.data.info = s[a.data.encrypt_table[c]](a.data.info)}}if (e)return a.data.info;var g = “”;for (c = 0; c < a.data.info.length; c++)g += String.fromCharCode(a.data.info[c]);return g}简单测试一下这个加密算法是不是正确,在代码后面加上两句。

    response.status === 304) {return response.data// 如果不需要除了data之外的数据,可以直接 return response.data} else if (response.status === 401) {location.href = ‘/login’;} else {throw response.data}} else {throw {data:’网络错误’}}}// axios默认参数配置axios.defaults.baseURL = ‘/api/v0’;axios.defaults.timeout = 10000;// restful API封装export default {post (url, data) {return axios({method: ‘post’,url,data: qs.stringify(data),headers: {‘X-Requested-With’: ‘XMLHttpRequest’,’Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’}}).then((res) => {return checkStatus(res)})},get (url, params) {return axios({method: ‘get’,url,params, // get 请求时带的参数headers: {‘X-Requested-With’: ‘XMLHttpRequest’}}).then((res) => {return checkStatus(res)})},del (url, params) {return axios({method: ‘delete’,url,params, // get 请求时带的参数headers: {‘X-Requested-With’: ‘XMLHttpRequest’}}).then((res) => {return checkStatus(res)})}}该模版只是一个大致框架,大家可以细化成业务需求的样子,该案例提供了restful接口方法,比如get/post/delete/put等。

    }        return requests.post(url, data=data).json()    def get_cookies(self, username, password):。

    $fp = fsockopen($URL_Info[“host”], $URL_Info[“port”]);。

    Similar Posts

    发表评论

    邮箱地址不会被公开。 必填项已用*标注