0340デフォルトの名無しさん
2020/04/02(木) 14:11:06.61ID:LyfVZOwj個別でURL、タイトルなど取得し無事に出力することができたのでページ内の全URLを出力してみたところ、
予定では別々な25件のURLが出力されると思ったのですが、
同じURLが220件出力されてしまいました。原因はenumerateの使い方が間違っている。
取得する場所が間違っているからだったりするのでしょうか?
import requests
import re
from bs4 import BeautifulSoup
page_url ="https://news.yahoo.co.jp/topics/top-picks"
r = requests.get(page_url)
soup = BeautifulSoup(r.text, features="html.parser")
item_list = soup.find_all(class_=re.compile(r"newsFeed*"))
for num,item in enumerate(item_list):
news_url = news.find(class_="newsFeed_item_link").get("href")
print("num:", num)
print("url", news_url)
print("*" * 100)