'save'에 해당되는 글 1건
- 2009.11.25 [python] 웹페이지 가져와서 파일로 저장하기
<웹페이지 가져와서 화면에 보여주기>
>>> from urllib import urlopen
>>> doc = urlopen("http://www.python.org").read()
>>> print doc
---+---
>>> import urllib
>>> uf = urllib.urlopen('http://www.python.org')
>>> doc = uf.read()
>>> print doc
---+--- reference : correct working code(py 3.0)
>>> import urllib.request
>>> uh = urllib.request.urlopen('http://www.python.org')
>>> h_source = uh.read()
>>> print(html)
>>> from urllib import urlopen
>>> doc = urlopen("http://www.python.org").read()
>>> print doc
---+---
>>> import urllib
>>> uf = urllib.urlopen('http://www.python.org')
>>> doc = uf.read()
>>> print doc
---+--- reference : correct working code(py 3.0)
>>> import urllib.request
>>> uh = urllib.request.urlopen('http://www.python.org')
>>> h_source = uh.read()
>>> print(html)
<웹페이지 내용을 파일로 저장하기>
>>> f = open("d:\\tmp\doc.html", 'w')
>>> print f 또는 print(f)
>>> f.write(doc)
>>> f.close
<저장한 html파일 열어서 읽어오기>
>>> f = open("d:\\tmp\\doc.html",'r')
>>> for line in f:
. . . print line
. . .
>>> f = open("d:\\tmp\doc.html", 'w')
>>> print f 또는 print(f)
>>> f.write(doc)
>>> f.close
<저장한 html파일 열어서 읽어오기>
>>> f = open("d:\\tmp\\doc.html",'r')
>>> for line in f:
. . . print line
. . .
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Python Programming Language -- Official Website</title>
<meta name="keywords" content="python programming language object oriented web free source" />
<meta name="description" content=" Home page for Python, an interpreted, interactive, object-oriented, extensible
.... 이하 생략
>>> f.close()
.... 이하 생략
>>> f.close()
Recent Comment