質問編集履歴

1

ファイルへ書き出す処理を追記

2022/12/04 07:47

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -18,9 +18,10 @@
18
18
  topics = soup.find(id = "Topics")
19
19
 
20
20
  # aタグとhref属性取得
21
+ with open("info.txt", "w") as w:
21
- for elem in topics.find_all("a"):
22
+ for elem in topics.find_all("a"):
22
- data = elem.text + "," + elem.get("href") # この部分!!
23
+ data = elem.text + "," + elem.get("href")
23
- print(data)
24
+ w.write(data + "\n")
24
25
 
25
26
  ```
26
27