프로그래밍언어/Python

html down (URLlib)url

부산딸랑이 2014. 8. 20. 05:01


import urllib.request
f = urllib.request.urlopen('http://www.daum.net')

print(f.read().decode('utf-8'))

import urllib.request
DATA=b'some data'
req = urllib.request.Request(url='http://localhost:8080', data=DATA,method='PUT')
f = urllib.request.urlopen(req)
print(f.status)
print(f.reason)



import urllib.request
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='PDQ Application',
                          uri='https://mahler:8092/site-updates.py',
                          user='klem',
                          passwd='kadidd!ehopper')
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
urllib.request.urlopen('http://www.example.com/login.html')


import urllib.request
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
opener.open('http://www.example.com/')




import urllib.request
req = urllib.request.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
r = urllib.request.urlopen(req)



>>> import urllib.request
>>> local_filename, headers = urllib.request.urlretrieve('http://python.org/')
>>> html = open(local_filename)
>>> html.close()


'프로그래밍언어 > Python' 카테고리의 다른 글

파이썬 url인코딩  (0) 2014.09.25
파일 다운로드  (0) 2014.09.25
REGEX  (0) 2014.09.17
어제날짜구하기  (0) 2014.08.20
파이썬 파일생성  (0) 2014.08.20