質問編集履歴
1
対象のhtmlとエラーについて追記しました. htmlの貼り方がこれではわかりにくいと思いますので, 実際にアクセスしていただけると助かります.
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,6 +14,16 @@
|
|
14
14
|
time = soup.select(".routeSummary li.time")[0].select("span")[0].text
|
15
15
|
```
|
16
16
|
|
17
|
+
```html
|
18
|
+
<dl class="routeSummary">
|
19
|
+
<dt>
|
20
|
+
<dd>
|
21
|
+
<ui>
|
22
|
+
<li class="time">
|
23
|
+
<span>22:40発→<span class="mark">22:54着</span></span>
|
24
|
+
|
25
|
+
```
|
26
|
+
|
17
27
|
### 試したこと
|
18
28
|
|
19
29
|
```python
|
@@ -21,4 +31,11 @@
|
|
21
31
|
time = soup.select("#route01 > dl > dd:nth-of-type(1) > ul > li.time > span").text
|
22
32
|
```
|
23
33
|
|
24
|
-
サイトの文法を理解することができなかったので, 私はchromeのcopyselectorを参考にして, その部分をこのコードに変えました
|
34
|
+
サイトの通りにやればもちろんうまくいきます. しかしサイトの文法を理解することができなかったので, 私はchromeのcopyselectorを参考にして, その部分をこのコードに変えました. しかし以下のようなエラーが出ます.
|
35
|
+
|
36
|
+
AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
|
37
|
+
|
38
|
+
エラーの意味もあまりわかりません.
|
39
|
+
|
40
|
+
あとhtmlへのリンクは以下のようになっています.
|
41
|
+
https://transit.yahoo.co.jp/search/result?flatlon=&fromgid=&from=%E6%9D%B1%E4%BA%AC&tlatlon=&togid=&to=%E6%96%B0%E5%AE%BF&viacode=&via=&viacode=&via=&viacode=&via=&y=2021&m=03&d=12&hh=22&m2=2&m1=5&type=1&ticket=ic&expkind=1&ws=3&s=0&al=1&shin=1&ex=1&hb=1&lb=1&sr=1&kw=%E6%96%B0%E5%AE%BF
|