MW211 EXIT

devlog
Python/Webスクレイピング(BeautifulSoup)
2020年05月11日
「urlopen」でHTMLを取得し、「BeautifulSoup」で解析する。
その土台となっているのが「Python」ていう感じ。
┌─────────────────┐    ┌─────────────────┐
│              urllib              │ → │          BeautifulSoup           │
│                                  │    │                                  │
│from urllib.request import urlopen│    │from bs4 import BeautifulSoup     │
│html = urlopen(URL).read()        │    │soup = BeautifulSoup(html,        │
│                                  │    │                     "html.parser")
├─────────────────┴──┴─────────────────┤
│                           Python(文法・関数など)                           │
│                                                                            │
│# 結果をファイル出力                                                        │
│f = open("出力.txt", "w", encoding="utf-8")                                 │
│f.write(文字列)                                                             │
│f.close()                                                                   │
│                                                                            │
│# 取得先に負荷をかけないよう間隔を空けることも忘れずに                      │
│from datetime import datetime                                               │
│from time import sleep                                                      │
│sleep(1)                                                                    │
└──────────────────────────────────────┘
分類:Python