LoginSignup
0
1

More than 1 year has passed since last update.

アメブロの記事をまとめて引っこ抜く

Last updated at Posted at 2021-12-21

つば九郎のブログを

  • URLからここだけ抽出する

2896-blog

getAmeblo.py "2896-blog" 200 #URL/取得記事数

結果

おは。 みなさん、しんぶんみた~ むらかみくん~ごいごいす~ですね~ でも、それだけのかつやくですね。 みなさん、きょう、らじおNIKKEI11:35~12:05『こづかあなの~ほめたいむ』きいてくださいね!radikoでもきけま
すので~ぜんこくのみなさん~よろしく~ぱちり。 にん。 うちあわせむしで、ありまきねんのよそうも~。 ↓くりっく~↓小塚アナの褒めタイム! | ラジオNIKKEIwww.radionikkei.jpらじおにっけいさんの、Twitterも、ちぇけら~!です。

ではきいてください。 m.c.A・Tで~BOMB A HEADBOMB A HEADm.c.A・T · Song · 1994open.spotify.com みんなえみふる。 ひょうばんよかったら、またよんでね~。おは。 みなさん、しんぶんみた~ むらかみくん~ごいごいす~
ですね~ でも、それだけのかつやくですね。 みなさん、きょう、らじおNIKKEI11:35~12:05『こづかあなの~ほめたいむ』きいてくださいね!radikoでもきけますので~ぜんこくのみなさん~よろしく~ぱちり。 にん。 う

コード

getAmeblo.py

import requests
import re
from bs4 import BeautifulSoup
import sys

# タグの除去
def cleanhtml(raw_html):
    cleanr = re.compile("<.*?>")
    cleantext = re.sub(cleanr, "", raw_html)
    return cleantext

# 記事の取得
def scraping(html):
    html = requests.get(html).content
    soup = BeautifulSoup(html, "lxml")
    text = soup.find("div", {"class", re.compile("skin-entryBody*")})
    return cleanhtml(str(text)).strip()

# メイン処理
def main():
    getTxt = ""
    for i in range(int(sys.argv[2])):
        url = f"https://ameblo.jp/{sys.argv[1]}/page-{i}.html"
        str_list = scraping(html=url).splitlines()
        text = "".join(str_list)
        getTxt += text
    print(getTxt)


if __name__ == "__main__":
    main()

拡張オプション

  • あなただけのオリジンを作ってクローン作ろう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1