import urllib import urllib2 req = urllib2.Request('http://9632024.tistory.com/974') try: urllib2.urlopen(req) except URLError, e: print e.reason fo = open("test1.html","w") for line in urllib2.urlopen(req).readlines(): fo.write(line) fo.close()
import urllib import urllib2 import string fo1 = open("test1.html", "r") fo2 = open("test2.html", "w") for line in fo1.readlines() : pos = string.find(line, '"http') if pos is not -1 : for c in range(pos+1, len(line)) : if line[c] is '"' : fo2.write("\n") break fo2.write(line[c]) fo1.close() fo2.close()
import urllib import urllib2 fo = open("test2.html", "r") for line in fo.readlines(): urllib.urlretrieve(line,line.split('/')[-1]) fo.close()
Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> first = 1 >>> second = 2 >>> first, second = second, first >>> print first 2 >>> print second 1 >>> first, second = second, first >>> third = 3 >>> first, second, third = third, first, second >>> print first, second, third 3 1 2
import os os.chdir(os.getcwd() + '/folder') def create_dir(folder): cdir = os.getcwd() mdir = cdir + folder print mdir; if os.path.isdir(mdir) is False : os.mkdir(mdir , 0755) type = ['/mp3', '/jpg', '/txt'] for t in type : create_dir(t)
import prepare import os currentpath = os.getcwd() path = os.getcwd() + '/luckyzzang' if os.path.isdir(path) is False : os.mkdir(path, 0755) os.chdir(path) currentpath = os.getcwd() for i in range(1, 21): url = 'http://comic.naver.com/webtoon/detail.nhn?titleId=449854&no=' + str(i) + '&weekday=wed' path = currentpath + '/' + str(i) if os.path.isdir(path) is False : os.mkdir(path, 0755) os.chdir(path) prepare.readpage(url, str(i) + '.html') prepare.extractwt(str(i) + '.html', str(i) + 'file.html') prepare.download(str(i) + 'file.html')