Web pages css, js, img file download save

# - * - Coding: UTF-. 8 - * - 
from BS4 Import the BeautifulSoup the BS AS 
 Import the urllib.request AS RQST 

HTML = rqst.urlopen (URL) 

# page by parsing bs 
bs = the BS (REQ, ' lxml ' ) 

# Get css , js, img routing file 
ELC = bs.find_all ( ' Link ' , type = ' text / CSS ' ) 
ELJ = bs.find_all ( ' Script ' , type = ' text / JavaScript ' ) 
Eli = bs.find_all ( ' img ')


#保存css,js,img文件
for c in elc:
   #还没完成
   url = c['href']
   name = url.split('/')[-1]

for i in eli:
   req = getRequest(i)
   res = rqst.urlopen(req)
   img = res.read()

   name = i.split('/')[-1]

   with open(name, 'wb') as f:
      f.write(img)
   f.close()  

 

Guess you like

Origin www.cnblogs.com/hanzg/p/10941838.html