반응형
wget class ][ robots.txt 받아오기
# -*- coding: utf-8 -*- # # write by kyoung chip , jang # # python 3.6 # pip list # import subprocess class CWget : def __init__( self ) : pass def getFile( self, location , url ) : proc = subprocess.Popen( ['wget', '-O',location, url], stdout = subprocess.PIPE ) out,err = proc.communicate() print ( ( "output = %s \nerror = %s") % ( out , err ) ) if __name__ == '__main__': w = CWget() w.getFile("c:\\k\python\\python\\robots.txt","https://www.google.com/robots.txt")
# # write by kyoung chip , jang # # python 3.6 # pip list # import urllib.request class CWget : def __init__( self ) : pass def getFile( self , location , url ) : urllib.request.urlretrieve( url , location ) if __name__ == '__main__': w = CWget() w.getFile( "c:\\k\\python\\python\\robots.txt" ,"https://www.google.com/robots.txt")
# # write by kyoung chip , jang # # python 3.6 # pip list # import urllib.request import shutil class CWget : def __init__( self ) : pass def getFile( self , file_name , url ) : with urllib.request.urlopen(url) as response, open(file_name, 'wb') as out_file: shutil.copyfileobj(response, out_file) if __name__ == '__main__': w = CWget() w.getFile( "c:\\k\\python\\python\\robots.txt" ,"https://www.google.com/robots.txt")
# -*- coding: utf-8 -*- # # write by kyoung chip , jang # # import urllib.request class CWget : def __init__( self ) : pass def getFile( self , file_name , url ) : with urllib.request.urlopen( url ) as response, open(file_name, 'wb') as out_file: data = response.read() out_file.write(data) if __name__ == '__main__': w = CWget() w.getFile( "c:\\k\\python\\python\\robots.txt" ,"https://www.google.com/robots.txt")
# -*- coding: utf-8 -*- # # write by kyoung chip , jang # # pip install requests # import requests class CWget : def __init__( self ) : pass def getFile( self , file_name , url ) : with open( file_name , "wb" ) as file: response = requests.get( url ) file.write( response.content ) if __name__ == '__main__': w = CWget() w.getFile( "c:\\k\\python\\python\\robots.txt" ,"https://www.google.com/robots.txt")
반응형
'Python > 0x01-url' 카테고리의 다른 글
html parser class ][ security focus title과 link정보 가져오기 (0) | 2017.10.05 |
---|---|
html parser class ][ 보안뉴스 가장 많이 본 뉴스 keyword 가져오기 (0) | 2017.10.03 |
request class (0) | 2017.10.03 |
url parser ][ CUrlParser (0) | 2017.10.03 |