0w0
[urllib] 파라미터 데이터 가져오기, API data 및 RSS 가져오기 본문
728x90
반응형
ip API json데이터 가져오기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import urllib.request as req
from urllib.parse import urlencode
#호스트 및 API 페이지
init_url="https://api.ipify.org"
values={
'format':'json'
}
print('before:',values)
params=urlencode(values)
print('after :',params)
print()
req_url=init_url+'?'+params
print('요청url',req_url)
data=req.urlopen(req_url).read().decode('utf-8')
print(data)
#출력결과
# before: {'format': 'json'}
# after : format=json
#
# 요청url https://api.ipify.org?format=json
# {"ip":"218.155.99.26"}
|
cs |
네이버에 고래 검색 데이터 가져오기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import urllib.request as req
from urllib.parse import urlencode
#호스트 및 API 페이지
init_url="https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&"
# https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EA%B3%A0%EB%9E%98
#고래 검색하기
values={
'query':'고래'
}
print('before:',values)
parameter=urlencode(values)
print('after :',parameter)
print()
req_url=init_url+parameter
print('요청url',req_url)
data=req.urlopen(req_url).read().decode('utf-8')
print(data)
#출력결과
# before: {'query': '고래'}
# after : query=%EA%B3%A0%EB%9E%98
#
# 요청url https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=%EA%B3%A0%EB%9E%98
# <!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <meta name="referrer" content="always"> <meta name="format-detection" content="telephone=no,address=no,email=no"> <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=2.0"> <meta property="og:title" content="고래 : 네이버 통합검색"/> <meta property="og:image" content="https://ssl.pstatic.net/sstatic/search/common/og_v3.png"> <meta property="og:description" content="'고래'의 네이버 통합검색 결과입니다."> <meta name="description" lang="ko" content="'고래'의 네이버 통합검색 결과입니다."> <title>고래 : 네이버 통합검색</title> <link rel="shortcut icon" href="https://ssl.pstatic.net/sstatic/search/favicon/favicon_140327.ico"> <link rel="search" type="application/opensearchdescription+xml" href="https://ssl.pstatic.net/sstatic/search/opensearch-description.https.xml" title="Naver" />
# ...생략
|
cs |
728x90
반응형
'Coding > Python' 카테고리의 다른 글
[parser] requests.get(), urllib.request.urlopen().read() (0) | 2019.08.20 |
---|---|
[BeautifulSoup] soup.find_all(), soup.find(), prettify() 적용 (0) | 2019.08.17 |
[selenium] zzzscore.com/color/ 2 솔랑솔랑 (0) | 2019.08.14 |
[selenium] zzzscore.com/color/ 솔랑솔랑 (0) | 2019.08.14 |
[selenium] zzzscore.com/1to50/ 솔랑솔랑 (0) | 2019.08.13 |
Comments