studying data

문제의 본질을 꿰뚫어 해결책을 찾는 법을 공부합니다

콤퓨타 공부/Python

[python 공부] 웹페이지 방문

study_data 2021. 8. 22. 17:44
  1. from-import를 이용해서 urllib패키지 안 request 모듈에서 urlopen 함수를 불러오는 코드를 작성해봅시다.
  2. 다음 주소를 urlopen하고, read() 한 다음, 이를 utf-8으로 decode 한 결과를 변수 webpage에 넣어봅시다.https://en.wikipedia.org/wiki/Lorem_ipsum   
  3. 변수 webpage를 출력해봅시다. 무엇이 나오나요?
 

Lorem ipsum - Wikipedia

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. It

en.wikipedia.org

 

정답코드

from urllib.request import urlopen

webpage = urlopen("https://en.wikipedia.org/wiki/Lorem_ipsum").read().decode(utf-8)

print(webpage)

 

내가 쓴 오답코드

from urllib import request
from request import urlopen

webpage = decode(read(urlopen("https://en.wikipedia.org/wiki/Lorem_ipsum")),utf-8)

print(webpage)

 

** 배운 점

- 패키지와 모듈은 온점(.)으로 연결하고 함수를 불러올 때 import 뒤에 위치시키기

- 함수를 연속해서 사용할 때는 온점(.) 이용해 순차적으로 이어서 사용함