回答編集履歴
2
全量のコードと出力結果の追加
answer
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
修正すると下の通りでしょうか。
|
3
3
|
|
4
4
|
```Python
|
5
|
+
import requests
|
6
|
+
from bs4 import BeautifulSoup
|
7
|
+
|
8
|
+
#食べログのURL
|
9
|
+
url = "https://tabelog.com/tokyo/A1301/A130103/R5266/rstLst/?vs=1&sa=%E6%96%B0%E6%A9%8B%E9%A7%85&sk=%25E5%2580%258B%25E5%25AE%25A4&lid=hd_search1&vac_net=&svd=20200323&svt=1900&svps=2&hfc=1&ChkRoom=1&cat_sk=%E5%80%8B%E5%AE%A4"
|
10
|
+
|
11
|
+
#タグ取得
|
12
|
+
response = requests.get(url)
|
13
|
+
soup = BeautifulSoup(response.content, 'html.parser')
|
14
|
+
restrants = soup.find_all("div", class_="list-rst__wrap js-open-new-window")
|
15
|
+
|
16
|
+
#テーブル作成
|
5
17
|
table = []
|
6
18
|
|
7
19
|
for restrant in restrants:
|
@@ -9,11 +21,27 @@
|
|
9
21
|
star = restrant.find("span", class_="list-rst__rating-val")
|
10
22
|
table.append([shopname.get_text(), shopname["href"], star.text])
|
11
23
|
|
12
|
-
|
13
24
|
import pandas as pd
|
14
25
|
|
15
26
|
Column = ['店舗名', 'URL', '点数']
|
16
27
|
|
17
28
|
# データフレームを作成
|
18
29
|
df = pd.DataFrame(table,columns=Column)
|
30
|
+
|
31
|
+
# CSV ファイル出力
|
32
|
+
df.to_csv(r"tabelog.csv",encoding='utf_8_sig')
|
33
|
+
```
|
34
|
+
|
35
|
+
## 出力結果
|
36
|
+
```csv
|
37
|
+
,店舗名,URL,点数
|
38
|
+
0,アンジェロ,https://tabelog.com/tokyo/A1301/A130101/13015364/,3.26
|
39
|
+
1,鳥元 虎ノ門店,https://tabelog.com/tokyo/A1308/A130802/13019433/,3.19
|
40
|
+
2,佐賀牛グリルイタリアン ドルチェヴィータ 銀座,https://tabelog.com/tokyo/A1301/A130101/13168844/,3.06
|
41
|
+
3,個室×ラクレットチーズ プラチナフィッシュ ガーデンキッチン ,https://tabelog.com/tokyo/A1301/A130103/13199175/,3.10
|
42
|
+
|
43
|
+
(中略)
|
44
|
+
|
45
|
+
18,本格中華食べ放題 天香府 新橋本店,https://tabelog.com/tokyo/A1301/A130103/13186435/,3.22
|
46
|
+
19,尾崎牛焼肉 銀座 ひむか,https://tabelog.com/tokyo/A1301/A130101/13193861/,3.54
|
19
47
|
```
|
1
誤字修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
forで
|
1
|
+
forでrestrantsの一番最後だけを処理しているようです。
|
2
2
|
修正すると下の通りでしょうか。
|
3
3
|
|
4
4
|
```Python
|