import json import urllib.request # True にするとユーザー名を隠す hide_user = False # 以下を書き換える。sys.argv 使ってもいいんだけど url1 = "https://www.cygames.co.jp/news/id-23172/" url2 = "https://mtg60.com/archives/palworlddoujinsi.html" def get_bookmarks(url: str): req = urllib.request.Request(f"https://b.hatena.ne.jp/entry/json/{url}") with urllib.request.urlopen(req) as res: dict = json.loads(res.read()) user_comments = {} for bookmark in dict["bookmarks"]: if bookmark["comment"]: user_comments[bookmark["user"]] = bookmark["comment"] return user_comments b1 = get_bookmarks(url1) b2 = get_bookmarks(url2) common = set(b1.keys()).intersection(b2.keys()) print(f"[1] {url1}") print(f"[2] {url2}") print() for user in sorted(common): if hide_user: print(user[0] + "*" * (len(user) - 1)) else: print(user) print(f"[1] {b1[user]}") print(f"[2] {b2[user]}") print()