【Python】requestsライブラリの使い方

GET

url = 'http://example.com'
headers = {'User-Agent': 'Mozilla/5.0'}

response = requests.get(url, headers=headers)

print(response.text)

POST

url_items = 'https://qiita.com/api/v2/items'

item_data = {
    'title': 'テスト記事',
    'body': 'テスト',
    'private': True,
    'tags': [{'name': 'test'}],
    'coediting': False,
    'gist': False,
    'tweet': False
}

r_post = requests.post(url_items, headers=headers, json=item_data)

Leave a Comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Scroll to Top