使安卓本地sdk中的文档能够打开

来源:互联网 发布:找淘宝兼职工作靠谱吗 编辑:程序博客网 时间:2024/05/22 15:51
这段python代码不能完全处理所有的细节,我把我自己完全处理过的文件上传到网盘:http://pan.baidu.com/s/1pJ9JFU7 

现在由于政府墙的原因,不能直接上安卓官网查看资料

下载sdk时,是通过更改hosts文件,下载下来后,里面会有个docs文件夹,这个也是安卓的官方文档。

但是由于里面需要引用谷歌的资源,所以打不开或者需要极长时间才能打开。

还有就是打开后,浏览器中有个东西会不停的再转啊转的加载东西。对有点强迫证的来说简直是个噩梦。

使用方法:

把下面的代码存成mvgoogle.py文件,放在docs 文件夹下。直接运行即可,使用的是python3.4。

import osulr_google = {'http://fonts.googleapis.com/css?family=Roboto+Condensed', 'http://fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold', 'http://www.google.com/jsapi', 'http://fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold', 'http://www.google.com/jsapi', '//swfobject.googlecode.com/svn/trunk/swfobject/swfobject.js', 'http://www.google-analytics.com/ga.js', 'http://fonts.googleapis.com/css?family=Roboto+Condensed', 'http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold','//www.google-analytics.com/analytics.js'}def readfile(filepath, mode='rt', encoding=None):fd = Noneif encoding:fd = open(filepath, mode=mode, encoding=encoding)else:fd = open(filepath, mode=mode)data = fd.read()fd.close()return datadef writefile(data, filepath, mode='w', encoding=None):fd = Noneif encoding:fd = open(filepath, mode=mode, encoding=encoding)else:fd = open(filepath, mode=mode)fd.write(data)fd.close()# def walk(dirpath, parser):def walk(dirpath):for root, subdirs, files in os.walk(dirpath):for file in files:if not file.endswith('.html'):continuefilepath = os.path.join(root, file)data = readfile(filepath, encoding="utf-8")for gu in ulr_google:data = data.replace(gu, '#')writefile(data, filepath, encoding="utf-8")curpath = os.getcwd()# parser = MyParser()walk(curpath)# ./assests/js/docs.js # move https://apis.google.com/js/plusone.jsdocsjs = os.path.sep.join((curpath, 'assets', 'js', 'docs.js'))data = readfile(docsjs)data = data.replace('https://apis.google.com/js/plusone.js', '#')writefile(data, filepath)

现在就能在本地快速自由地打开文档了。

0 0
原创粉丝点击