[{"data":1,"prerenderedAt":169},["ShallowReactive",2],{"\u002Fother_memorandum\u002Fpython":3},{"id":4,"title":5,"body":6,"date":160,"description":161,"draft":162,"extension":163,"meta":164,"navigation":55,"path":165,"seo":166,"stem":167,"__hash__":168},"blog\u002F900.other_memorandum\u002F05.python.md","Pythonについて",{"type":7,"value":8,"toc":155},"minimark",[9,14,22,134,138,151],[10,11,13],"h2",{"id":12},"python-http通信で情報取得する","Python HTTP通信で情報取得する",[15,16,17,21],"p",{},[18,19,20],"code",{},"python","がインストールできていれば、以下でOK。",[23,24,28],"pre",{"className":25,"code":26,"language":20,"meta":27,"style":27},"language-python shiki shiki-themes github-light","import sys\nimport json \nimport urllib.request\n\n## 取得したい情報のURL\nurl = \"取得したい情報のURL\"\nheader = {\n  # 例えば header に仕込む key-value\n  'key': 'value', \n  # 例えば header に仕込む 認証情報\n  'Authorization': 'Bearer \u003CYOUR TOKEN>'\n}\nreq = urllib.request.Request(url, headers = header)\n\nwith urllib.request.urlopen(req) as res:\n    body = json.load(res)\n    print(body)\n\n","",[18,29,30,38,44,50,57,63,69,75,81,87,93,99,105,111,116,122,128],{"__ignoreMap":27},[31,32,35],"span",{"class":33,"line":34},"line",1,[31,36,37],{},"import sys\n",[31,39,41],{"class":33,"line":40},2,[31,42,43],{},"import json \n",[31,45,47],{"class":33,"line":46},3,[31,48,49],{},"import urllib.request\n",[31,51,53],{"class":33,"line":52},4,[31,54,56],{"emptyLinePlaceholder":55},true,"\n",[31,58,60],{"class":33,"line":59},5,[31,61,62],{},"## 取得したい情報のURL\n",[31,64,66],{"class":33,"line":65},6,[31,67,68],{},"url = \"取得したい情報のURL\"\n",[31,70,72],{"class":33,"line":71},7,[31,73,74],{},"header = {\n",[31,76,78],{"class":33,"line":77},8,[31,79,80],{},"  # 例えば header に仕込む key-value\n",[31,82,84],{"class":33,"line":83},9,[31,85,86],{},"  'key': 'value', \n",[31,88,90],{"class":33,"line":89},10,[31,91,92],{},"  # 例えば header に仕込む 認証情報\n",[31,94,96],{"class":33,"line":95},11,[31,97,98],{},"  'Authorization': 'Bearer \u003CYOUR TOKEN>'\n",[31,100,102],{"class":33,"line":101},12,[31,103,104],{},"}\n",[31,106,108],{"class":33,"line":107},13,[31,109,110],{},"req = urllib.request.Request(url, headers = header)\n",[31,112,114],{"class":33,"line":113},14,[31,115,56],{"emptyLinePlaceholder":55},[31,117,119],{"class":33,"line":118},15,[31,120,121],{},"with urllib.request.urlopen(req) as res:\n",[31,123,125],{"class":33,"line":124},16,[31,126,127],{},"    body = json.load(res)\n",[31,129,131],{"class":33,"line":130},17,[31,132,133],{},"    print(body)\n",[135,136,137],"h3",{"id":137},"参考",[139,140,141],"ul",{},[142,143,144],"li",{},[145,146,150],"a",{"href":147,"rel":148},"https:\u002F\u002Fqiita.com\u002Fhoto17296\u002Fitems\u002F8fcf55cc6cd823a18217",[149],"nofollow","Python の HTTP クライアントは urllib.request で十分 #Python - Qiita",[152,153,154],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":27,"searchDepth":40,"depth":40,"links":156},[157],{"id":12,"depth":40,"text":13,"children":158},[159],{"id":137,"depth":46,"text":137},"2026-06-14T07:00:00+09:00","Pythonの備忘録です。",false,"md",{},"\u002Fother_memorandum\u002Fpython",{"title":5,"description":161},"900.other_memorandum\u002F05.python","1B2Mn9OEOC6cmO6U-0y7R93lGbxHgcp3hr7x6eakKi4",1781530000702]