前提・実現したいこと
pythonで
https://www.eigonews.net/blog/
このサイトをスクレイピングして今日の記事とリンクを取得しようとしています。
しかし、全く違う要素が取得されてしまいます。
何が起きているのでしょうか。
該当のソースコード
python
1url = "https://www.eigonews.net/blog/" 2headers = {"User-Agent": "hoge"} 3 4res = requests.get(url, headers=headers) 5soup = BeautifulSoup(res.content, "html.parser") 6 7# today = dt.datetime.today().strftime("%Y-%m-%d") 8today = "2019-06-03" # 06/04 の記事はなかったので、テスト用に前日の日付を設定 9 10for article in soup.find_all(class_="media-body"): 11 published = article.find(class_="published").string # 記事の日付 12 if published != today: 13 continue # 今日の日付でない場合はスキップ 14 15 # 記事のリンクとタイトルを取得 16 header = article.find(class_="media-heading") 17 18 link = header.a["href"] 19 title = header.string 20 msg = title + '\n' + link 21 print(msg)
###実行結果
今週の復習494【Weekly Review 494】
https://www.eigonews.net/weekly-review-494/
###期待している結果
トランプ氏が国賓としての訪日を終了【Trump concludes state visit to Japan】
https://www.eigonews.net/trump-concludes-state-visit-to-japan/
試したこと
サイトの構造は変わっていないようでした。
補足情報(FW/ツールのバージョンなど)
python3,windows10
回答1件
あなたの回答
tips
プレビュー