컴퓨터/프로그래밍

웹에서 텍스트 가져오기

review777777 2011. 8. 5. 03:26
반응형

웹에서 텍스트 가져오기

import urllib.request

import time

price=99.99

while price> 4.74:

time.sleep(900)

page = urllib.request.urlopen("http://www.beans-r-us.biz/prices-loyalty.html")

text = page.read().decode("utf8")

where=text.find('>$')

start_of_price=where+2

end_of_price=start_of_price+4

price=float(text[start_of_price:end_of_price])

print("Buy!")

 

 

 

import urllib.request

page= urllib.request.urlopen(“인터넷주소”)

text = page.read().decode(“utf8”)

print(text)

-> 인터넷 웹상에서 그 웹 텍스트 전부 가져올 수 있음.

 

 

 

time.sleep(900)

-> 900초 즉 15분동안 아무것도 하지않음.

 

 

 

 

 

where=text.find(">$")

-> 주어진 텍스트에서 >$를 찾아 >$ 첫 번째 인덱스 값.

 

price=float(text[start_of_price:end_of_price])

-> text[가져올라는 텍스트의 첫번째텍스트가 몇 번째 숫자인지:가져올라는 텍스트의 마지막텍스트가 몇 번째 숫자인지]

int형은 소수점자리까지 나타나지 않으니까 float형을 씀.

 

반응형

'컴퓨터 > 프로그래밍' 카테고리의 다른 글

chapter 02  (0) 2011.08.05
1부터 100까지 숫자중 임의의 숫자 추측하기  (0) 2011.08.05
python 처음 시작하기  (0) 2011.08.05
05-07  (0) 2011.06.16
05-04  (0) 2011.06.16
05-02  (0) 2011.05.11
04-03  (0) 2011.05.11