回答編集履歴

1

追記

2020/03/24 22:21

投稿

CHERRY
CHERRY

スコア25175

test CHANGED
@@ -39,3 +39,115 @@
39
39
  # 1件分の項目取得処理を書く
40
40
 
41
41
  ```
42
+
43
+
44
+
45
+ ----
46
+
47
+ 2020.03.25 追記
48
+
49
+
50
+
51
+ 質問のコードを流用して、下記のコードを書いて試してみました。
52
+
53
+
54
+
55
+ ```Python
56
+
57
+ import requests
58
+
59
+ from bs4 import BeautifulSoup
60
+
61
+
62
+
63
+ 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"
64
+
65
+
66
+
67
+ response = requests.get(url)
68
+
69
+ soup = BeautifulSoup(response.content, 'html.parser')
70
+
71
+ restrants = soup.find_all("div", class_="list-rst__wrap js-open-new-window")
72
+
73
+
74
+
75
+ for restrant in restrants:
76
+
77
+ shopname = restrant.find("a", class_="list-rst__rst-name-target cpy-rst-name")
78
+
79
+ star = restrant.find("span", class_="list-rst__rating-val")
80
+
81
+ print('name:{} url:{} star:{}'.format(shopname.text, shopname.get("href"), star.text))
82
+
83
+ ```
84
+
85
+ のプログラムを実行したところ
86
+
87
+
88
+
89
+ ```
90
+
91
+ name:アンジェロ url:https://tabelog.com/tokyo/A1301/A130101/13015364/ star:3.26
92
+
93
+ name:鳥元 虎ノ門店 url:https://tabelog.com/tokyo/A1308/A130802/13019433/ star:3.19
94
+
95
+ name:佐賀牛グリルイタリアン ドルチェヴィータ 銀座 url:https://tabelog.com/tokyo/A1301/A130101/13168844/ star:3.06
96
+
97
+ name:おば九 新橋駅前店 url:https://tabelog.com/tokyo/A1301/A130103/13110976/ star:3.19
98
+
99
+ name:伍法 url:https://tabelog.com/tokyo/A1301/A130103/13127305/ star:3.48
100
+
101
+ name:個室×ビストロ Borghini 新橋店 url:https://tabelog.com/tokyo/A1301/A130103/13234671/ star:3.09
102
+
103
+ name:個室×ラクレットチーズ プラチナフィッシュ ガーデンキッチン url:https://tabelog.com/tokyo/A1301/A130103/13199175/ star:3.10
104
+
105
+ name:ぬる燗 佐藤 銀座店 url:https://tabelog.com/tokyo/A1301/A130103/13195789/ star:3.40
106
+
107
+ name:大衆酒場 一升瓶 url:https://tabelog.com/tokyo/A1301/A130103/13185179/ star:3.06
108
+
109
+ name:神戸牛しゃぶしゃぶ・焼肉 嵯峨野 url:https://tabelog.com/tokyo/A1301/A130103/13047097/ star:3.09
110
+
111
+ name:MEAT KITCHEN 新橋店 url:https://tabelog.com/tokyo/A1301/A130103/13217264/ star:3.02
112
+
113
+ name:福炎や url:https://tabelog.com/tokyo/A1301/A130103/13047799/ star:3.29
114
+
115
+ name:わびさび SHINOBI url:https://tabelog.com/tokyo/A1301/A130103/13027344/ star:3.33
116
+
117
+ name:入母屋 別邸 銀座七丁目店 url:https://tabelog.com/tokyo/A1301/A130101/13019693/ star:3.42
118
+
119
+ name:銀座むらき url:https://tabelog.com/tokyo/A1301/A130101/13014857/ star:3.34
120
+
121
+ name:南国亭 新橋日比谷店 url:https://tabelog.com/tokyo/A1301/A130103/13200776/ star:3.03
122
+
123
+ name:東京立ち飲みバル url:https://tabelog.com/tokyo/A1301/A130103/13148777/ star:3.24
124
+
125
+ name:炭の屋でですけ url:https://tabelog.com/tokyo/A1301/A130103/13132578/ star:3.34
126
+
127
+ name:車 銀座8丁目店 url:https://tabelog.com/tokyo/A1301/A130103/13043449/ star:3.09
128
+
129
+ name:銀座柊家 url:https://tabelog.com/tokyo/A1301/A130102/13221080/ star:3.10
130
+
131
+ ```
132
+
133
+ となり、Webブラウザ(シークレットモード/プライベートモード)で確認してみた感じでは、
134
+
135
+
136
+
137
+ ![イメージ説明](4fb272aaae2ea57056fbcf0393559b1f.png)
138
+
139
+
140
+
141
+ と同じ結果になっていました。
142
+
143
+
144
+
145
+
146
+
147
+ > AttributeError: 'NoneType' object has no attribute 'text'
148
+
149
+
150
+
151
+ のエラーの件ですが、API 側から返ってくるデータに依存していると思われるのですが、手元では再現しないので具体的な原因は不明です。
152
+
153
+ エラーメッセージ的には、`<span class_="list-rst__rating-val">〜</span> が取得できない(返ってくるデータにない?)のだと思います。