Computers/Language python

procedure

emzei 2012. 3. 14. 16:27


parameter can be <name>, <name>, ... 

def <name> (<parameters>):

<block>





page =  ... contents of some web page ...

start_link = page.find('<a href=')

start_quote = page.find('"',start_link)

end_quote=gape.find('"',start_quote+1)

url = page[start_quote+1:end_quote]

print url # first url on the page


# repeat

page = page[end_quote:]                           # page 값을 update

start_link = page.find('<a href=')

start_quote = page.find('"',start_link)

end_quote= page.find('"',start_quote+1)

url = page[start_quote+1:end_quote]

print url # second url on the page



보라색 부분을 procedure로 만들기

procedure name : get_next_target

input : string giving contents of the rest of the web page

output : url, end_quote


    ↓ representing the string (page)

def get_next_target( s ): 

start_link = s.find('<a href=')

start_quote = s.find('"',start_link)

end_quote=s.find('"',start_quote+1)

url = s[start_quote+1:end_quote]

return url, end_quote



'Computers > Language python' 카테고리의 다른 글

Loops / loop  (0) 2012.03.14
if statement  (0) 2012.03.14
url 링크 얻기  (0) 2012.03.14
web crawler - extract link  (0) 2012.03.14
파이썬 문자열 string find  (0) 2012.03.14