標籤:python android開發 api
原因大家應該都知道,離線下載的SDK Api本地也無法開啟,其實主要就是因為這些Doc中有去訪問google的一些網站:font、js api等等,因此,要真正離線使用Doc,有兩個方法可以實現:
1、真正的離線——即把網斷掉,這樣確實可以,但是,使用起來太不方便了
2、把API Doc中的所有請求font、js api的內容都刪掉,不過,這個過程太痛苦了,API Doc有幾萬個檔案,總不能一個個刪,所以,祭出Python,秒秒鐘搞定,代碼如下:
import oss1 = ‘‘‘<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto">‘‘‘s2 = ‘‘‘<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto+Condensed">‘‘‘s3 = ‘‘‘<script type="text/javascript" async="" src="https://apis.google.com/js/plusone.js"></script>‘‘‘s4 = ‘‘‘<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js"></script>‘‘‘for root,dirs,files in os.walk(r‘/data/SDK/sdk/docs‘): for file in files: fd = root + os.sep + file if ".html" in fd: print fd f = open(fd, ‘r‘) s = f.read().replace(s1, "").replace(s2, "").replace(s3, "").replace(s4, "") f.close() f = open(fd, ‘w‘) f.write(s) f.close()
使用時只要將os.walk的路徑修改成doc的路徑即可,運行後很快就能完成全部的替換,如果碰到某些頁面還是打不開,只需要開啟原始碼,找到訪問google的請求加入到指令碼中進行替換即可。
以上。
通過Python處理Android API Doc離線訪問