teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

2018/10/25 06:15

投稿

tiitoi
tiitoi

スコア21960

answer CHANGED
@@ -10,4 +10,23 @@
10
10
 
11
11
  ![イメージ説明](5d7100b98d02b5368310b8ef7b36e2f7.png)
12
12
 
13
- XPath については[こちら](https://webbibouroku.com/Blog/Article/xpath)を参考にするとよいかと思います。
13
+ XPath については[こちら](https://webbibouroku.com/Blog/Article/xpath)を参考にするとよいかと思います。
14
+
15
+ ## 追記
16
+
17
+ XPath 自体はあっていることを示すために上記のことを紹介しました。
18
+ 以下のコードで取得した HTML を保存したところ、
19
+
20
+ ```
21
+ with open('test.html', 'w') as f:
22
+ f.write(response.body.decode("utf-8"))
23
+ ```
24
+
25
+ Yahoo Japan を見るための環境を満たしていないと判断され、弾かれています。
26
+ なので、ブラウザでアクセスしたときの HTML は取得できていないため、上記の XPath が指す要素も存在しませんでした。
27
+
28
+ ```
29
+ <nobr>Yahoo! JAPANトップページの機能を正しくご利用いただくには、下記の環境が必要です。</nobr><br>
30
+ Windows:Internet Explorer 11.0以上 / Chrome 最新版 / Firefox 最新版 / Microsoft Edge Macintosh:Safari 9.0以上<img src="//s.yimg.jp/images/clear.gif" alt="" width="1" height="15"><br>
31
+ ※Internet Explorer 11.0以上をご利用の場合は、「<a href="https://www.yahoo-help.jp/app/answers/detail/p/533/a_id/43883">Internet Explorerの互換表示について</a>」を参考に、互換表示の無効化をお試しください。<img src="//s.yimg.jp/images/clear.gif" alt="" width="1" height="15"><br><img src="//s.yimg.jp/images/clear.gif" alt="" width="1" height="15">
32
+ ```