YongArtist
2016. 11. 21. 19:12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import urllib2 url = "http://www.pythonchallenge.com/pc/def/ocr.html" # url 값 str로 저장 response = urllib2.urlopen(url).read() # urlopen으로 url을 열고 read로 값을 읽은 후 response에 저장 string = response[response.rindex('<!--'):response.rindex('-->')] # 뒤에서 부터 <!--의 인덱스와 -->이 위치한 인덱스의 값을 통해 슬라이싱 # 한 후에 string에 저장 result='' for i in string: #isalpha()는 알파벳이면 true를 반환하는데 string에 알파벳이 있으면 result에 문자를 추가 if i.isalpha(): result +=i print result | cs |
urllib2을 처음 써보는데 되게 흥미롭다. 앞으로 자주 보게 되면 좋겠는데..