<jupyter_start><jupyter_text>GET<jupyter_code>import requests

resp = requests.request('get','http://httpbin.org/get',params={'Key':'Value'})
resp.status_code, resp.headers, resp.content<jupyter_output><empty_output><jupyter_text>POST<jupyter_code>resp = requests.request('post','http://httpbin.org/post',params={'Key':'Value'})
resp.status_code, resp.headers, resp.content
from urllib import parse

header = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}

def getDownload(url, params={}, retries=3):
    resp = None
    
    try:
        resp = requests.get(url, params=params, headers=header)
        resp.raise_for_status()
    except requests.exceptions.HTTPError as e:
        if 500 <= e.response.status_code < 600 and retries > 0:
            print(retries)
            resp = getDownload(url, params, retries-1)
        else:
            print(e.response.status_code)
            print(e.response.reason)
            print(e.response.headers)
            
    return resp
html = getDownload('http://httpbin.org/get',{'Key':'Value'})
html.text, html.content<jupyter_output><empty_output><jupyter_text>http://www.crawler-test.com/status_codes/status_  (Error Test Url) status_ 뒤에 뭐가 붙냐에 따라 Error가 달라짐 ex) status_403<jupyter_code>html = getDownload('http://www.crawler-test.com/status_codes/status_500')
url = 'http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getCtprvnRltmMesureDnsty'
params = {
    'serviceKey':'uUV3bYpGK%2B%2FKA%2ByjKHJ7UMoD2TVkEqcBP71WikTHPqyM6%2ByOufXY2%2BTerSXcPkeIM58OHp9A3qt9TP14WdsZHQ%3D%3D',
    'numOfRows':10,
    'pageNo':1,
    'sidoName':'인천',
    'ver':1.3,
    '_returnType':'json'
}
result = getDownload(url, params)
result.text
result.url
org = requests.utils.unquote(params['serviceKey'])
params['serviceKey'] = org
result = getDownload(url, params)
import json
result = json.loads(result.text)
for row in result['list']:
    print(row['stationName'], row['pm25Value'])<jupyter_output>신흥 12
송림 13
구월동 8
숭의 12
석바위 15
부평역 16
부평 11
연희 14
검단 15
계산 16<jupyter_text>http://pythonscraping.com/pages/files/form.html  Test Url<jupyter_code>url = 'http://pythonscraping.com/pages/files/form.html'

html = getDownload(url, {'firstname':'1234','lastname':'1234'})
html.request.headers
html.text
url = 'http://pythonscraping.com/pages/files/processing.php'

html = getDownload(url, {'firstname':'1234','lastname':'1234'})
html.request.body
html.text
html = requests.post(url, {'firstname':'1234','lastname':'1234'})
html.request.body<jupyter_output><empty_output><jupyter_text>Cookie 이용 방식  Before<jupyter_code>url = 'http://pythonscraping.com/pages/cookies/welcome.php'

html = requests.post(url, {'username':'test','password':'password'})
html.text<jupyter_output><empty_output><jupyter_text>After<jupyter_code>html.cookies.get_dict()
html = requests.get(url, cookies=html.cookies)
html.text<jupyter_output><empty_output><jupyter_text>Session 이용 방식<jupyter_code>session = requests.Session()
html = session.post(url, {'username':'test','password':'password'})
html = session.post(url)
html.text<jupyter_output><empty_output><jupyter_text>www.timetime.kr Session Test  DATA 일치<jupyter_code>url = 'http://www.timetime.kr/user/login'
data = {'username':'누구게요','password':'<PASSWORD>'}
session = requests.Session()
html = session.post(url, data)
html.text<jupyter_output><empty_output><jupyter_text>DATA 불일치<jupyter_code>data = {'username':'누구게요','password':'<PASSWORD>'}
session = requests.Session()
html = session.post(url, data)
html.text<jupyter_output><empty_output><jupyter_text>교보문고<jupyter_code>url = 'http://'
params={
    'vPStrCategory':'TOT',
    'vPstrKeyWrod';'hi',
    'vPplace':'top'
}
html = request.post(url,params)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16157894736842104, 'fraction_numerical': 0.030263157894736843, 'mean_word_length': 5.824057450628366, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '495638', 'license': 'Apache-2.0', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1531, 'n_words': 197, 'path': 'week1/20190502_Cookie_Session.ipynb', 'repo_name': 'mssung94/ai-innovation-square', 'size': '3793'}