通過Python處理Android API Doc離線訪問

來源:互聯網
上載者:User

標籤: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離線訪問

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.