想從一個網頁下載zip包,查看源檔案發現下載檔案的連結有一定的特徵,因此花了半個小時寫了個指令碼,很簡單,因為對函數不熟悉還查看了文檔,用的時間長了一點。
指令碼執行過後,直接把地址複製到迅雷裡就可以一下下載很多個檔案了,不用一個一個的去點了,哈哈~
urls = '''<li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_1.1_-_Challenging_Problems-subtitles.en.zip">Unit_1.1_-_Challenging_Problems-subtitles.en.zip</a> - 38.6KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_1.2_-_Algorithm_Analysis_and_the_RAM-subtitles.en.zip">Unit_1.2_-_Algorithm_Analysis_and_the_RAM-subtitles.en.zip</a> - 49.6KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_1.3_-_Big_O_%28Optional%29-subtitles.en.zip">Unit_1.3_-_Big_O_(Optional)-subtitles.en.zip</a> - 29.3KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_1.4_-_Connecting_Similar_Problems-subtitles.en.zip">Unit_1.4_-_Connecting_Similar_Problems-subtitles.en.zip</a> - 68.6KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_2.1_-_Many_Solutions_and_Intractability-subtitles.en.zip">Unit_2.1_-_Many_Solutions_and_Intractability-subtitles.en.zip</a> - 33.4KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_2.2_-_Non-deterministic_RAM-subtitles.en.zip">Unit_2.2_-_Non-deterministic_RAM-subtitles.en.zip</a> - 54.1KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_2.3_-_SAT-subtitles.en.zip">Unit_2.3_-_SAT-subtitles.en.zip</a> - 40.5KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_2.4_-_Proof_of_SAT_%28Optional%29-subtitles.en.zip">Unit_2.4_-_Proof_of_SAT_(Optional)-subtitles.en.zip</a> - 74.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_2.5_-_NP-Completeness_Via_Reductions-subtitles.en.zip">Unit_2.5_-_NP-Completeness_Via_Reductions-subtitles.en.zip</a> - 52.5KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_3_-_Solving_NP-Complete_Problems-subtitles.en.zip">Unit_3_-_Solving_NP-Complete_Problems-subtitles.en.zip</a> - 108.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_4.1_-_Pruning_the_Input-subtitles.en.zip">Unit_4.1_-_Pruning_the_Input-subtitles.en.zip</a> - 91.6KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_4.2_-_Preprocessing-subtitles.en.zip">Unit_4.2_-_Preprocessing-subtitles.en.zip</a> - 31.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_4.3_-_Measuring_Hardness-subtitles.en.zip">Unit_4.3_-_Measuring_Hardness-subtitles.en.zip</a> - 49.3KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_5.1_-__Approximation_Factor-subtitles.en.zip">Unit_5.1_-__Approximation_Factor-subtitles.en.zip</a> - 54.1KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_5.2_-_Shortest_Tour-subtitles.en.zip">Unit_5.2_-_Shortest_Tour-subtitles.en.zip</a> - 25.3KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_5.3_-_Reductions_&_Approx._Factors-subtitles.en.zip">Unit_5.3_-_Reductions_&_Approx._Factors-subtitles.en.zip</a> - 19.9KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_5.4_-_PTAS-subtitles.en.zip">Unit_5.4_-_PTAS-subtitles.en.zip</a> - 42.2KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_6.1_-_Randomization-subtitles.en.zip">Unit_6.1_-_Randomization-subtitles.en.zip</a> - 76.4KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_6.2_-_What_Youve_Learnt-subtitles.en.zip">Unit_6.2_-_What_Youve_Learnt-subtitles.en.zip</a> - 51.4KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_7.1_-_Limits_of_Computation-subtitles.en.zip">Unit_7.1_-_Limits_of_Computation-subtitles.en.zip</a> - 68.5KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Unit_7.2__-_More_Undecidability-subtitles.en.zip">Unit_7.2__-_More_Undecidability-subtitles.en.zip</a> - 60.4KB</li></ul><hr><ul><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_1-subtitles.en.zip">Problem_Set_1-subtitles.en.zip</a> - 41.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_2-subtitles.en.zip">Problem_Set_2-subtitles.en.zip</a> - 25.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_3-subtitles.en.zip">Problem_Set_3-subtitles.en.zip</a> - 20.7KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_4-subtitles.en.zip">Problem_Set_4-subtitles.en.zip</a> - 30.2KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_5-subtitles.en.zip">Problem_Set_5-subtitles.en.zip</a> - 18.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_6-subtitles.en.zip">Problem_Set_6-subtitles.en.zip</a> - 13.8KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Problem_Set_7-subtitles.en.zip">Problem_Set_7-subtitles.en.zip</a> - 14.3KB</li><li><a rel="nofollow" href="https://s3.amazonaws.com/udacity-serving-videos/zip/cs313/Exam-subtitles.en.zip">Exam-subtitles.en.zip</a> - 13.8KB</li></ul>'''end = 0while urls.find('<a rel="nofollow" href="', end) != -1: start = urls.find('<a rel="nofollow" href="', end) + len('<a rel="nofollow" href="') end = urls.find('">', start) print urls[start:end]
輸出結果是每行一個需要下載的檔案的地址,因此直接複製到迅雷裡就可以了,還是挺方便的。