Android Development Help Docs doc Open slow solve _python article

Source: Internet
Author: User

Fix Android help document open slow

The Netizen said is because the doc directory in the HTML file contains access to Google js file

<link rel= "stylesheet" href= "Http://,medium,thin,italic, Mediumitalic,bold "title=" Roboto ">

<script src= "Http://" type= "Text/javascript" ></script>
It is true that this has been checked.

Since these two lines of script need to access Google online, it is obvious that subsequent content loading will slowly and slowly ...

What do we do?

Open the. html file in each directory to manually delete the top two lines of content? Will definitely delete the pain. It was suggested that:

method One: Modify the Hosts file

This solution, Modify the Hosts file in the C:\WINDOWS\system32\drivers\etc directory to add

The speed will improve a lot.

method Two: Write the Java program Bulk annotation

Traverse all files in the doc directory, delete the top two lines of each file, refer to

/* * Remove JavaScript code that requires networking in Android documents */import;import;import ; Import;import;import;import;public class Formatdoc {public static int j=1; /** * @param args */public static void main (string[] args) {File file = new file ("d:/android/a        Ndroid-sdk-windows/docs/");        Searchdirectory (file, 0);    System.out.println ("over"); } public static void Searchdirectory (File f, int depth) {if (!f.isdirectory ()) {String fileName = f            . GetName (); if (Filename.matches (". *.{ 1}html ")) {String src= < (link rel) [=]\" (stylesheet) \ "\ n (HREF) [=]\] (HTTP)://(FONTS.GOOGLEAPIS.COM/CSS) [ ?] (family) [=] (Roboto) [:]                (Regular,medium,thin,italic,mediumitalic,bold) \ "(title) [=]\" roboto\ ">"; String src1 = "<script src=\"\ "type=\" Text/javascript\ "></script>";                String DST = "";                If it is an HTML file, comment out the specific JavaScript code annotation (f, SRC, DST);            Annotation (f, src1, DST);            }} else {file[] fs = F.listfiles ();            depth++;                for (int i = 0; i < fs.length; ++i) {File file = Fs[i];            Searchdirectory (file, depth); }}}//* F to modify the contents of the file * src will be replaced content * DST will be replaced with the content of the layer */public static void annotation (File F, string src, string dst)        {String content = (f);        Content = Content.replacefirst (src, DST);        int Ll=content.lastindexof (SRC);        System.out.println (LL);        Formatdoc.write (content, f);        System.out.println (j + +);    Return        public static String read (File src) {stringbuffer res = new StringBuffer ();        String line = null; try {BufferedReader reader = new BufferedreadER (new FileReader (SRC));            int i=0;                while (line = Reader.readline ()) = null) {if (i!=0) {res.append (' \ n ');                } res.append (line);            i++;        } reader.close ();        } catch (FileNotFoundException e) {e.printstacktrace ();        } catch (IOException e) {e.printstacktrace ();    } return res.tostring (); public static Boolean write (String cont, File Dist) {try {bufferedwriter writer = new Bufferedwri            ter (new FileWriter (Dist));            Writer.write (cont);            Writer.flush ();            Writer.close ();        return true;            } catch (IOException e) {e.printstacktrace ();        return false; }    }}

method Three: Execute the script

Through the shell to delete the line JS code, very simple and convenient, than the above Java convenient 100 times times, but can not delete the first section of JS code.

Find. -name "*.html" |xargs grep-l "Jsapi" |xargs sed-i '/jsapi/d '
I haven't tried.

Life is short, I use Python

method Four: Python code bulk Delete

Idea: Traverse the doc or docs directory and subdirectories, find all. html files, open these files, read the contents of the file, replace the above JS content is empty, write the changes back to the file, the end.

It's complicated, and it's really simple to implement in Python.

Import Oss1 = "<link rel=" stylesheet "href=" Http://,medium,thin, Italic,mediumitalic,bold "title=" Roboto ">" s2 = "<script src=" Http:// "type=" text/ JavaScript "></script>" s3 = "<script type=" Text/javascript "async=" "src=" Https:// /plusone.js "></script>" s4 = "<script type=" Text/javascript "async=" "src="/HTTP/ "></script>" for Root,dirs,files in Os.walk (R ' C:\AndroidSdk\docs '):    For file in Files:        fd = root + os.sep + file        if ". html" in FD:            print fd            f = open (fd, ' R ')            s = () . replace (S1, ""). Replace (S2, ""). Replace (S3, ""). Replace (S4, "")            F.close ()            f = open (fd, ' W ')            F.write (s)            F.close ()      

Caught dead explained that, assuming that my Android development help document under C:\androidsdk\docs, traversing all directories and filenames under it can only be done with the OS walk function.

For Root,dirs,files in Os.walk (R ' C:\AndroidSdk\docs '):
The walk return value, the directory root that is currently traversed, what subdirectories are under it dirs, what files are available, and what is important is recursive traversal of the specified directory C:\AndroidSdk\docs.

Get rid of the HTML file two of the effect of the speed of JS, the first HTML file,

    For file in Files:        fd = root + os.sep + file
All file names are constructed to find (match). html files just like this

        If ". html" in FD:            print FD
Next is to kill the shadow display (speed) of the JS, the replacement file in the corresponding content is empty.

f = open (fd, ' r ') s = (). Replace (S1, ""). Replace (S2, ""). Replace (S3, ""). Replace (            S4, "")            F.close ()            f = Open (FD, ' W ')            f.write (s)            f.close ()

Run it, 1 minutes to run the end of the entire docs under a total of more than 9,000 files, traversal, read and write time.

Finally find a doc and try C:\AndroidSdk\docs\reference\android\widget\Spinner.html.

The speed, the leverage.

I'm using a python2.7.5.

Oh, welcome to reply to criticism! or Praise!

Python Https://

Android Development Help Docs doc Open slow solve _python article

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.