乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      python爬蟲下載網(wǎng)站所有文件

       LibraryPKU 2019-03-27

      核心思路是使用正則表達式對網(wǎng)頁的html5中的路徑名和文件名進行抓取,

      然后對路徑繼續(xù)進行同樣的抓取,用遞歸的方式進行搜索。最后把網(wǎng)站上的內(nèi)容文件全部下載下來

      import urllib

      import sys
      import BeautifulSoup
      import re
      import os

      path = []

      def extract(url):
          content = urllib.urlopen(url).read()
          #reg = r'(?:href|HREF)="?((?:http://)?.+?\.txt)'    
          reg = r'<a href="(.*)">.*'
          url_re = re.compile(reg)
          url_lst = re.findall(url_re, content)

          for lst in url_lst:
              ext = lst.split('.')[-1]
          
              if ext[-1] == '/':
                 newUrl = url + lst
                 extract(newUrl)
              else:
                  path.append(url + lst)
             


      print "downloading with urllib"
      url = 'http://139.196.233.65/js/'
      extract(url)

      filePath = 'E:/6-學習文檔/91-JS/Download/js'
      filePath = unicode(filePath, 'utf8')

      for p in path:
          fileTitle = p.split('/js')[-1]
          file = filePath + fileTitle
          dir = os.path.dirname(file)
          isExists=os.path.exists(dir)

          if isExists == False:
              os.makedirs(dir)
          urllib.urlretrieve(p, file)






      #for lst in url_lst:
      #    file = filePath + lst
      #    lst = url + '/' + lst
      #    urllib.urlretrieve(lst, file)




        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多